Web -Schaber Python Mongo DB -Abfrage funktioniert nichtPython

Python-Programme
Anonymous
 Web -Schaber Python Mongo DB -Abfrage funktioniert nicht

Post by Anonymous »

Ich bin ziemlich neu im Programmieren und lerne derzeit Python. Ich habe ein Web -Scraper -Projekt mit Python und wunderschöner Suppenbibliothek unten, in der ich einen ganzen Artikel von einer Nachrichten -Webseite kratze.

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)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post