Added try catch for scraper functions
This commit is contained in:
parent
9c76ea38ce
commit
9c63ada6e5
@ -2,8 +2,11 @@ import requests
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
def query_external_website(base_url, query):
|
def query_external_website(base_url, query):
|
||||||
page = requests.get(base_url + query)
|
try:
|
||||||
soup = BeautifulSoup(page.content, "html.parser")
|
page = requests.get(base_url + query)
|
||||||
title = soup.find("span", class_="mw-page-title-main").text
|
soup = BeautifulSoup(page.content, "html.parser")
|
||||||
content = soup.find(id="mw-content-text").select("p")[2].text
|
title = soup.find("span", class_="mw-page-title-main").text
|
||||||
return "\nTITLE:\n" + title + "\n\nCONTENT:\n" + content + "\n\nFULL LINK:\n" + base_url + query
|
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
|
||||||
|
except:
|
||||||
|
return "Can't parse search result :("
|
||||||
|
Loading…
Reference in New Issue
Block a user