본문 바로가기
코딩공부

220123 [코딩공부] 워드크라우드 만들기

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

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

url='https://class101.net/search?page=1&query=%EC%9C%A0%ED%88%AC%EB%B8%8C&sort=latestOrder'
driver.get(url)

first_sel=driver.find_element(By.CLASS_NAME,"GridList__Container-sc-1qd26lc-0.ixdUmO")
second_sel=first_sel.find_elements(By.TAG_NAME,"li")

news_title_lists=[]
for a in second_sel:
    news_title_lists.append(a.text.split("\n")[1:3])
news_title_lists

import pandas as pd
df=pd.DataFrame(news_title_lists)
df.to_excel('220123.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('wordcloud_news2.png')

댓글