Advertisement
Guest User

네이버뉴스

a guest
Apr 5th, 2020
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. import requests
  3.  
  4. base_url = 'https://news.naver.com/main/main.nhn?mode=LSD&mid=shm&sid1='
  5. category = [100, 101, 102, 103, 104, 105] #정치, 경제, 사회, 생활문화, 세계, 생활과학
  6. category = [100]
  7.  
  8. for i in category:
  9.     URL = base_url + str(i)
  10.     response = requests.get(URL)
  11.     soup = BeautifulSoup(response.text, "html.parser")    
  12.     results = soup.select(".section_list_ranking li a")
  13.  
  14.     for idx, tag in enumerate(results):
  15.         print(f"{idx:>02} : {tag.text}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement