본문 바로가기
코딩공부

220123-3 [코딩공부] 네이버금융 많이본뉴스 크롤링 및 워드크라우드 만들기

by Just J.S. 2022. 1. 23.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
s = Service('c:/users/smile/desktop/chromedriver.exe')
driver = webdriver.Chrome(service=s)

url='https://finance.naver.com/news/news_list.naver?mode=RANK'
driver.get(url)

news_title=driver.find_element(By.CLASS_NAME,"hotNewsList")
news_title2=news_title.find_elements(By.TAG_NAME,"a")

news_title_lists=[]
for a in news_title2:
    news_title_lists.append(a.text)
news_title_lists

import pandas as pd
df=pd.DataFrame(news_title_lists)
df.to_excel('navernewslist.xlsx')

!pip install wordcloud
import sys
from wordcloud import WordCloud
filename=sys.argv[1]
wc=WordCloud(font_path="BMJUA_ttf.ttf")
wc.generate(str(news_title_lists))
wc.to_file('navernewslist.png')

댓글