Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
606 B
2
Indexable
Never
import requests
from bs4 import BeautifulSoup

url = 'https://vnexpress.net/'

try:
    response = requests.get(url)
    response.raise_for_status()
except requests.exceptions.HTTPError as http_err:
    print(f"Có lỗi HTTP: {http_err}")
except requests.exceptions.RequestException as req_err:
    print(f"Có lỗi trong quá trình gửi yêu cầu: {req_err}")
else:
    soup = BeautifulSoup(response.text, 'html.parser')
    title_tags = soup.find_all(class_='title-news')
    for title_tag in title_tags:
        title_text = title_tag.get_text().strip()  
        print(title_text)