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')
'코딩공부' 카테고리의 다른 글
220211[코딩공부기록] Matplotlib 이용 그래프 그리기 (0) | 2022.02.11 |
---|---|
220123-2 [코딩공부] 쥬피터 노트북에서 wordcloud 설치 오류시 해결방법 (1) | 2022.01.23 |
220123 [코딩공부] 워드크라우드 만들기 (0) | 2022.01.23 |
220120 [코딩공부] 넷플릭스크롤링 영화제목가져오기 (0) | 2022.01.22 |
220122 [코딩공부] 넷플릭스 크롤링 엑셀 저장하기 (0) | 2022.01.22 |
댓글