Web -Schaber Python Mongo DB -Abfrage funktioniert nicht

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Web -Schaber Python Mongo DB -Abfrage funktioniert nicht

by Anonymous » 26 Aug 2025, 09:06

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)

Top