Skip to content

Commit cc8f276

Browse files
authored
Merge pull request #1 from stanbiryukov/SB_dep_packages
enable navigating through Package toggle for dependents
2 parents 751bc90 + 95df62d commit cc8f276

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

github_to_sqlite/utils.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,31 @@ def ensure_db_shape(db):
708708

709709

710710
def scrape_dependents(repo, verbose=False):
711+
from bs4 import BeautifulSoup
712+
url = "https://github.com/{}/network/dependents".format(repo)
713+
response = requests.get(url)
714+
soup = BeautifulSoup(response.content, "html.parser")
715+
# Navigate through Package toggle if present
716+
options = soup.find_all("a", class_="select-menu-item")
717+
links = []
718+
if len(options) > 0:
719+
for link in options:
720+
links.append(link['href'])
721+
else:
722+
links.append(f"{repo}/network/dependents")
723+
724+
if verbose:
725+
print(links)
726+
727+
for link in links:
728+
yield from _scrape_dependents(f"https://github.com/{link}", verbose=verbose)
729+
730+
731+
732+
def _scrape_dependents(url, verbose=False):
711733
# Optional dependency:
712734
from bs4 import BeautifulSoup
713735

714-
url = "https://github.com/{}/network/dependents".format(repo)
715736
while url:
716737
if verbose:
717738
print(url)

0 commit comments

Comments
 (0)