"파이썬 네이버 뉴스 키워드 검색"의 두 판 사이의 차이

 
(같은 사용자의 중간 판 하나는 보이지 않습니다)
(차이 없음)

2021년 6월 14일 (월) 22:11 기준 최신판

1 개요[ | ]

파이썬 네이버 뉴스 키워드 검색
  • 지정한 키워드로 검색하여 첫번째 기사의 제목과 URL을 추출한다.
import requests
from bs4 import BeautifulSoup

keyword = '코로나'
r = requests.get(f'https://search.naver.com/search.naver?where=news&query={keyword}')
soup = BeautifulSoup(r.text, 'html.parser')
articles = soup.select('ul.list_news > li')
title = articles[0].select_one('a.news_tit')['title']
url = articles[0].select_one('div.info_group > a:nth-of-type(2)')['href'] 
print('title=', title)
print('url=', url)

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}