Skip to content

Commit

Permalink
google_scholar.py: Added try...catch to improve robustness to network…
Browse files Browse the repository at this point in the history
… issues
  • Loading branch information
ibgp2 committed Apr 19, 2023
1 parent bd6ef67 commit 082d306
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/minifold/google_scholar.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,19 @@ def parse(self, s_html: str):
Args:
s_html (str): An HTML Google Scholar page content.
Raises:
``RuntimeError`` if the result can't be fetched from Google scholar.
"""
soup = SoupKitchen.make_soup(s_html)
soup = soup.find(name="div", attrs={"id": "gs_res_ccl_mid"})
for div in soup.findAll(name="div", attrs={"class": "gs_r"}):
s = div.prettify()
entry = parse_article(s)
self.articles.append(entry)
try:
soup = SoupKitchen.make_soup(s_html)
soup = soup.find(name="div", attrs={"id": "gs_res_ccl_mid"})
for div in soup.findAll(name="div", attrs={"class": "gs_r"}):
s = div.prettify()
entry = parse_article(s)
self.articles.append(entry)
except:
raise RuntimeError(f"Unable to parse:\n\n{s_html}")

def send_query(self, gs_query: ScholarQuery):
"""
Expand Down

0 comments on commit 082d306

Please sign in to comment.