forked from Decentrala/chatbot
Raise exception on None content
This commit is contained in:
parent
6df3c82a7e
commit
d4d14806db
@ -8,6 +8,8 @@ def query_external_website(base_url, 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 = next((paragraph for paragraph in soup.find(id="mw-content-text").select("p") if not paragraph.has_attr("class")), None)
|
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)
|
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