forked from Decentrala/chatbot
Get first available paragraph from query
This commit is contained in:
parent
41e38ef80f
commit
6df3c82a7e
@ -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 :("
|
||||||
|
Loading…
Reference in New Issue
Block a user