Scraping GitHub Profile using Python

Web scraping is one of the most valuable skills every coder should have. If you want to learn how to collect data from GitHub using web scraping techniques, this article is for you. In this article, I will take you through a web scraping tutorial on scraping GitHub profile using Python.

Scraping GitHub Profile using Python

When we open any GitHub account, we see a profile picture, the name of the user, and a short description of the user in the profile section. Here you will learn how to scrape your GitHub profile image. For this task, you need some knowledge of HTML and the requests and BeautifulSoup libraries in Python.

If you have never used the BeautifulSoup library before, use the command mentioned below in your command prompt or terminal to install this library in your Python virtual environment:

  • pip install beautifulsoup4

You don’t need to install the requests library as it is already present in the Python standard library. Now below is how to write a Python program to scrape a profile image from any GitHub profile:

import requests
from bs4 import BeautifulSoup as bs

github_profile = "https://github.com/amankharwal"
req = requests.get(github_profile)
scraper = bs(req.content, "html.parser")
profile_picture = scraper.find("img", {"alt": "Avatar"})["src"]
print(profile_picture)
Output:
https://avatars.githubusercontent.com/u/57987909?v=4

Now, if you click on the link you got as an output, you will see the profile picture of the GitHub user. This is how you can scrape profile images from any GitHub profile using Python.

Summary

So this is how you can scrape a GitHub profile using the Python programming language. Web scraping is one of the most valuable skills every coder should have. So you should know how to scrape images from any website using web scraping techniques. I hope you liked this article on scraping any GitHub profile using Python. Feel free to ask valuable questions in the comments section below.

Default image
Aman Kharwal

Coder with the ♥️ of a Writer || Data Scientist | Solopreneur | Founder

Articles: 1297

Leave a Reply