chatbot/scraper_functions.py

13 lines
506 B
Python
Raw Normal View History

2024-02-06 01:21:53 +00:00
import requests
from bs4 import BeautifulSoup
def query_external_website(base_url, query):
2024-02-06 01:37:19 +00:00
try:
page = requests.get(base_url + 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
except:
return "Can't parse search result :("