Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scrape-dependents: enable paging through package menu option if present #70

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion github_to_sqlite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,31 @@ def ensure_db_shape(db):


def scrape_dependents(repo, verbose=False):
from bs4 import BeautifulSoup
url = "https://github.com/{}/network/dependents".format(repo)
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
# Navigate through Package toggle if present
options = soup.find_all("a", class_="select-menu-item")
links = []
if len(options) > 0:
for link in options:
links.append(link['href'])
else:
links.append(f"{repo}/network/dependents")

if verbose:
print(links)

for link in links:
yield from _scrape_dependents(f"https://github.com/{link}", verbose=verbose)



def _scrape_dependents(url, verbose=False):
# Optional dependency:
from bs4 import BeautifulSoup

url = "https://github.com/{}/network/dependents".format(repo)
while url:
if verbose:
print(url)
Expand Down