Mundo em Python

Correio da Manhã

import time
import requests
from bs4 import BeautifulSoup def extrair_manchetes_e_textos(url):
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
manchetes = soup.find_all('a', class_='eventAnalytics')
textos = soup.find_all('p', class_='destaques_lead')
for manchete, texto in zip(manchetes,textos):
print("\033[32m" + manchete.text.strip() + "\033[m")
print("\033[34m" + texto.text.strip() + "\033[m")
except Exception as e:
print("Ocorreu um erro:", e) url = 'https://www.cmjornal.pt/'

headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36'
} while True:
extrair_manchetes_e_textos(url)
print("Atualização.")
time.sleep(3600)
0