카테고리 없음
scraping the headlines from the CNN website
DeNarO
2023. 1. 19. 14:13
import requests
from bs4 import BeautifulSoup
url = 'https://www.cnn.com/'
#네이버로 바꾸고 싶으면 www.naver.com
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
headlines = soup.find_all('h2', class_='cd__headline')
for headline in headlines:
print(headline.text.strip())