From 9c63ada6e51eb917a5f33dd6663ed8f4c2c07d9c Mon Sep 17 00:00:00 2001 From: texhno Date: Tue, 6 Feb 2024 02:37:19 +0100 Subject: [PATCH] Added try catch for scraper functions --- scraper_functions.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scraper_functions.py b/scraper_functions.py index 2f0445a..5b9cd9f 100644 --- a/scraper_functions.py +++ b/scraper_functions.py @@ -2,8 +2,11 @@ import requests from bs4 import BeautifulSoup def query_external_website(base_url, query): - page = requests.get(base_url + query) - soup = BeautifulSoup(page.content, "html.parser") - title = soup.find("span", class_="mw-page-title-main").text - content = soup.find(id="mw-content-text").select("p")[2].text - return "\nTITLE:\n" + title + "\n\nCONTENT:\n" + content + "\n\nFULL LINK:\n" + base_url + query + try: + page = requests.get(base_url + query) + soup = BeautifulSoup(page.content, "html.parser") + title = soup.find("span", class_="mw-page-title-main").text + content = soup.find(id="mw-content-text").select("p")[2].text + return "\nTITLE:\n" + title + "\n\nCONTENT:\n" + content + "\n\nFULL LINK:\n" + base_url + query + except: + return "Can't parse search result :("