From d4d14806db20f72abeb9ba5110e428d8440aee1a Mon Sep 17 00:00:00 2001 From: texhno Date: Tue, 6 Feb 2024 03:37:26 +0100 Subject: [PATCH] Raise exception on None content --- scraper_functions.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scraper_functions.py b/scraper_functions.py index 42178c7..d1061b6 100644 --- a/scraper_functions.py +++ b/scraper_functions.py @@ -8,6 +8,8 @@ def query_external_website(base_url, query): soup = BeautifulSoup(page.content, "html.parser") title = soup.find("span", class_="mw-page-title-main").text content = next((paragraph for paragraph in soup.find(id="mw-content-text").select("p") if not paragraph.has_attr("class")), None) + if content == None: + raise Exception("Can't parse") return "\nTITLE:\n" + title + "\n\nCONTENT:\n" + content.text + "\n\nFULL LINK:\n" + base_url + quote(query) except: return "Can't parse search result :("