Skip to content

Instantly share code, notes, and snippets.

@jgarte
Forked from iamaziz/github-repo-stars.py
Created December 29, 2020 20:09
Show Gist options
  • Save jgarte/56802da286890d06f99faf606dd925fe to your computer and use it in GitHub Desktop.
Save jgarte/56802da286890d06f99faf606dd925fe 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