From 2f69f1d3b67ffedc2f255e9d744ff60971868259 Mon Sep 17 00:00:00 2001 From: Patrick Mueller Date: Tue, 16 Aug 2022 22:07:04 +0200 Subject: [PATCH] Adding try except block in case of connection errors --- crawler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crawler.py b/crawler.py index e57e99e..914cfe2 100644 --- a/crawler.py +++ b/crawler.py @@ -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')