Notice
Recent Posts
Recent Comments
Link
«   2025/03   »
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 26 27 28 29
30 31
Tags
more
Archives
Today
Total
관리 메뉴

금융을 따라 흐르는 블로그

scraping the headlines from the CNN website 본문

카테고리 없음

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())