def get_soup(url, num_retries = 10):
"""
Takes in a url and returns the parsed BeautifulSoup code for that url with
handling capabilities if the request 'bounces'.
"""
s = requests.Session()
retries = Retry(
total = num_retries,
backoff_factor = 0.1,
status_forcelist = [500, 502, 503, 504]
)
s.mount('http://', HTTPAdapter(max_retries = retries))
return BeautifulSoup(s.get(url).text, 'html.parser')
评论列表
文章目录