네이버 기사 가져오기
조회수 548회
https://m.search.naver.com/search.naver?where=m_news&query=1%EB%B3%B4&sm=mtb_tnw&sort=1
위 링크에서 노출되는 기사의 제목을 제일 최근 것부터 시작해 20개의 기사 제목들을 가져오려면 경로 지정을 어떻게 해줘야 하나요??
api_txt_lines tit 까지는 찾았는데 그 다음을 어떻게 해야 할지 모르겠습니다.
1 답변
-
BeautifulSoup를 활용하여 쉽게 구현할 수 있습니다.
속보 기사 제목을 출력하는 파이썬 코드입니다.
from bs4 import BeautifulSoup import urllib.request # html 소스 가져오기 url = 'https://m.search.naver.com/search.naver?where=m_news&query=1%EB%B3%B4&sm=mtb_tnw&sort=1' with urllib.request.urlopen(url) as response: html = response.read() soup = BeautifulSoup(html, 'html.parser') articles = soup.find_all('div', {'class': 'api_txt_lines tit'}) # 기사 제목 가져오기 # 기사 제목 출력하기 for article in articles: title = article.text print(title)
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력