Adding try except block in case of connection errors

This commit is contained in:
Patrick Müller 2022-08-16 22:07:04 +02:00
parent fbdfdc287b
commit 2f69f1d3b6
Signed by: Paddy
GPG Key ID: 37ABC11275CAABCE
1 changed files with 4 additions and 1 deletions

View File

@ -35,7 +35,10 @@ class Crawler:
return articles
def __download_url__(self, url):
return requests.get(url, headers=HEADERS).text
try:
return requests.get(url, headers=HEADERS).text
except requests.exceptions.ConnectionError:
print('An error has occured trying to download the HTML')
def __extract_article_urls__(self, source) -> []:
soup = BeautifulSoup(source, 'html.parser')