Correct url link from multiword wiki query

This commit is contained in:
texhno 2024-02-06 02:58:45 +01:00
parent 0813460e8b
commit 41e38ef80f

View File

@ -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 :("