You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# requests 모듈을 읽어옴
import requests
from bs4 import BeautifulSoup
url = "https://news.naver.com/main/main.nhn?mode=LSD&mid=shm&sid1=101"# request.get() 메서드를 호츨해서 읽어온 데이터를 html에 담는다.
result_requests = requests.get(url)
print(type(result_requests))
# HTML 소스 가져오기
html = result_requests.text
# 첫번째 매개변수에 HTML을 지정한다.# 두번째 매개 변수에는 분석할 분석기(parser)의 종류를 지정한다. HTML을 분석할 때는 “html.parser”라고 지정한다.
bs_obj = BeautifulSoup(html, "html.parser")
#main_content > div > div._persist > div:nth-child(1) > div:nth-child(1) > div.cluster_body > ul > li:nth-child(1) > div.cluster_text > a
news_headline = bs_obj.select(
'div > div > div > div > div > ul > li > div > a'
)
# print(news_headline)# print(lis)forliin news_headline:
print(li.text)
The text was updated successfully, but these errors were encountered: