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

Enable timeouts when getting soup #36

Merged
merged 3 commits into from
Feb 15, 2024
Merged
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
14 changes: 11 additions & 3 deletions src/bioversions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,17 @@ def norm(s: str) -> str:
return s.lower().replace(" ", "").replace("-", "").replace(".", "")


def get_soup(url: str, verify: bool = True) -> BeautifulSoup:
"""Get a beautiful soup parsed version of the given web page."""
res = requests.get(url, verify=verify)
def get_soup(url: str, verify: bool = True, timeout: Optional[int] = None) -> BeautifulSoup:
"""Get a beautiful soup parsed version of the given web page.

:param url: The URL to download and parse with BeautifulSoup
:param verify: Should SSL be used? This is almost always true,
except for Ensembl, which makes a big pain
:param timeout: How many integer seconds to wait for a response?
Defaults to 15 if none given.
:returns: A BeautifulSoup object
"""
res = requests.get(url, verify=verify, timeout=timeout or 15)
soup = BeautifulSoup(res.text, features="html.parser")
return soup

Expand Down
Loading