Extraer una noticia con WebScaping en Python
Publicado por Carla Montes (1 intervención) el 26/05/2020 21:01:42
Hola, alguien me podría ayudar un poco, necesito extraer el titulo, url, cuerpo de una noticia de la pagina del mostrador, el titulo lo deja muy por debajo, la url queda bien, pero el cuerpo no lo encuentra y no me tira ni error ni nada. este es mi código.
Porfavor y gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import requests
from bs4 import BeautifulSoup
class Content:
def __init__(self, url, title, body):
self.url = url
self.title = title
self.body = body
def getPage(url):
req = requests.get(url)
return BeautifulSoup(req.text, 'html.parser')
def scrapeElmostrador(url):
bs = getPage(url)
title = bs.find("h2",{"class","titulo-single"}).text
body = bs.find("p",{"id":"noticia"}).text
return Content(url, title, body)
url = 'https://www.elmostrador.cl/noticias/pais/2020/05/26/coronavirus-chile-supera-la-barrera-de-800-fallecidos-y-contagiados-llegan-a-mas-de-77-mil/'
content = scrapeElmostrador(url)
print('Title: {}'.format(content.title))
print('URL: {}\n'.format(content.url))
print(content.body)
Porfavor y gracias
Valora esta pregunta


0