Code: Select all
import pymongo
import requests
url ="https://www.bbc.com/news/articles/cy081nqx2zjo"
response = requests.get(url)
from bs4 import BeautifulSoup
soup =BeautifulSoup(response.text,'html.parser')
paragraphs = soup.find_all("p")
for paragraph in paragraphs:
print(paragraph.text)
def check(paragraphs):
if len(paragraphs) > 100:
return "extracted fine"
else:
return "An exception occurred"
print(check(paragraphs))
mydict={}
doc = {"paragraphs":mydict}
from pymongo import MongoClient
client= pymongo.MongoClient("mongodb://localhost:27017")
db =client["mydb"]
collection=db["summarizer"]
collection.insert_one(doc)