From 41e38ef80fabf6e3971e2cae3401ec2c3ea667a0 Mon Sep 17 00:00:00 2001 From: texhno Date: Tue, 6 Feb 2024 02:58:45 +0100 Subject: [PATCH] Correct url link from multiword wiki query --- scraper_functions.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scraper_functions.py b/scraper_functions.py index 5b9cd9f..831366d 100644 --- a/scraper_functions.py +++ b/scraper_functions.py @@ -1,12 +1,13 @@ import requests from bs4 import BeautifulSoup +from urllib.parse import quote def query_external_website(base_url, query): try: - page = requests.get(base_url + query) + page = requests.get(base_url + quote(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 + return "\nTITLE:\n" + title + "\n\nCONTENT:\n" + content + "\n\nFULL LINK:\n" + base_url + quote(query) except: return "Can't parse search result :("