Get first available paragraph from query

This commit is contained in:
texhno 2024-02-06 03:34:43 +01:00
parent 41e38ef80f
commit 6df3c82a7e

View File

@ -7,7 +7,7 @@ def query_external_website(base_url, query):
page = requests.get(base_url + quote(query)) page = requests.get(base_url + quote(query))
soup = BeautifulSoup(page.content, "html.parser") soup = BeautifulSoup(page.content, "html.parser")
title = soup.find("span", class_="mw-page-title-main").text title = soup.find("span", class_="mw-page-title-main").text
content = soup.find(id="mw-content-text").select("p")[2].text content = next((paragraph for paragraph in soup.find(id="mw-content-text").select("p") if not paragraph.has_attr("class")), None)
return "\nTITLE:\n" + title + "\n\nCONTENT:\n" + content + "\n\nFULL LINK:\n" + base_url + quote(query) return "\nTITLE:\n" + title + "\n\nCONTENT:\n" + content.text + "\n\nFULL LINK:\n" + base_url + quote(query)
except: except:
return "Can't parse search result :(" return "Can't parse search result :("