본문 바로가기
Python

[네이버]뉴스 댓글 메모장파일까지 저장

by 퍼포먼스마케팅코더 2017. 1. 23.
반응형

import time

from selenium import webdriver

from bs4 import BeautifulSoup



comments = open("C:/Users/eyeden-FF14/Desktop/comments.txt", 'w' , encoding='utf-8' )

browser = 'C:/Users/eyeden-FF14/Desktop/Python/Selenium/chrome/chromedriver.exe'

driver = webdriver.Chrome(browser)

driver.get('http://entertain.naver.com/comment/list?oid=109&aid=0003467821')

time.sleep(3)

for i in range(0, 10) :

      driver.find_element_by_css_selector(".u_cbox_btn_more").click()

      time.sleep(3)

      i +=1


html = driver.page_source

bs = BeautifulSoup(html, 'html.parser')

contents = bs.find_all("span", {"class" : "u_cbox_contents"})

for i in contents :

      comments.write(str(i) + '\n')

comments.close()

반응형

댓글