Get articles from NAVER

Asked 2 years ago, Updated 2 years ago, 53 views

https://m.search.naver.com/search.naver?where=m_news&query=1%EB%B3%B4&sm=mtb_tnw&sort=1

How do I route the subject of the article exposed in the link above to get 20 article titles, starting with the most recent one?

I found the api_txt_linesit, but I don't know what to do next.

python crawling naver

2022-09-21 12:38

1 Answers

Beautiful Soup makes it easy to implement.

Python code to print the title of the breaking news article.

from bs4 import BeautifulSoup
import urllib.request

# Import html source
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.found_all('div', {'class': 'api_txt_linesit'}) # Get article title

# To print out the article title
for article in articles:
    title = article.text
    print(title)


2022-09-21 12:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.