I have this exercise: Identify which are the fields that must be imported from the extracted urls, what type of data must be saved for each of them. and on the imported data filter by the appropriate categories. Make code that allows such an import to be performed. This is my code but it doesn't print anything. I'm a beginner
from bs4 import BeautifulSoup import requests url = "https://www.senado.gov.co/index.php/el-senado/noticias" response = requests.get(url) soup = BeautifulSoup(response.content, "html.parser") # Obtener todas las noticias noticias = soup.find_all("div", class_="articulo-contenido") # Recorrer cada noticia y obtener los datos de interés for noticia in noticias: titulo = noticia.find("h2").text.strip() fecha = noticia.find("div", class_="fecha").text.strip() categoria = noticia.find("span", class_="categoria").text.strip() enlace = noticia.find("a")["href"] # Filtrar las noticias que cumplen con cierta condición if enlace.startswith("https://www.senado.gov.co/index.php/el-senado/noticias/item/"): print(titulo, fecha, categoria, enlace)
article article-intro-image article-body article-header article-info article-introtext
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)