Skip to content

Instantly share code, notes, and snippets.

@iamaziz
Last active December 29, 2020 20:09
Show Gist options
  • Save iamaziz/24072d0e44e9da38fb33eb2397fc21f5 to your computer and use it in GitHub Desktop.
Save iamaziz/24072d0e44e9da38fb33eb2397fc21f5 to your computer and use it in GitHub Desktop.
Scrape the stars count of a GitHub repo (beautifulSoup)
from bs4 import BeautifulSoup as bs
import requests
def stars_count(url):
html = requests.get(url).text
soup = bs(html, 'lxml')
stars_class = "social-count js-social-count"
stars = soup.find('a', class_=stars_class).text.strip()
return stars
repo = 'https://github.com/TensorFlow/TensorFlow'
print(stars_count(repo))
# out: 43,939
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment