속보로 검색한 뉴스 검색 결과와 1보로 검색한 뉴스 검색 결과를 모두 출력하도록 하고 싶은데 어떻게 수정해야 하나요??
아래의 방법으로 사용하고있는데 지저분해 보여서요..
빠르고 친절한 답변을 주신 이루노님께 감사하지만 가능하면 큰 틀의 수정 없이 search_word 부분만 수정해서 사용하는 방법이 궁금합니다!!
import requests
from bs4 import BeautifulSoup
search_word = '속보'
url = f'https://search.naver.com/search.naver?where=news&query=
{search_word}&sm=tab_srt&sort=1'
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
news_titles = soup.select('.news .type01 li dt a[title]')
print()
for title in news_titles:
print(title['title'])
search_word = '1보'
url = f'https://search.naver.com/search.naver?where=news&query=
{search_word}&sm=tab_srt&sort=1'
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
news_titles = soup.select('.news .type01 li dt a[title]')
print()
for title in news_titles:
print(title['title'])