from bs4 import BeautifulSoup
import requests
search_word = "파이썬"
#실제링크 qurey=파이썬 --> 파이썬 빼고 {}로 입력
url = 'https://search.naver.com/search.naver?where=news&sm=tab_jum&query={}'.format(search_word)
req = requests.get(url)
if req.ok:
html = req.text
soup = BeautifulSoup(html, 'html.parser')
titles_by_select = soup.select(
'ul.type01 > li > dl > dt > a'
)
for title in titles_by_select:
print(title.get('title'))