Skip to content

Commit

Permalink
feat: print html code of the page and raise an error if no selected e…
Browse files Browse the repository at this point in the history
…lement;
  • Loading branch information
WenjieDu committed Apr 28, 2023
1 parent 9749067 commit bd796aa
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gsbg/google_scholar_badge_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def fetch_selected_element_from_page(selector: str, page_url: str) -> bs4.elemen
page = requests.get(page_url).text
soup = BeautifulSoup(page, "html.parser")
selected = soup.select_one(selector)
if selected is None:
print(soup.prettify())
raise RuntimeError(
f"Cannot find the element selected by {selector} on {page_url}. "
f"This may caused by an invalid selector, an invalid page_url. "
f"The reason also may be your IP address got blocked by the server. "
f"The fetch html page got printed above, please check it to find more details."
)
return selected


Expand Down

0 comments on commit bd796aa

Please sign in to comment.