learning-assistance / functions.py
Alberto Carmona
Use the function to extract the text
92bb964
raw
history blame
305 Bytes
import requests
from bs4 import BeautifulSoup
def extract_text(url: str):
if url is None or url.strip() == '':
return ''
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
text = '\n\n'.join(map(lambda p: p.text, soup.find_all('p')))
return text