개발, 연습

[웹 크롤러] 파이썬 웹 크롤러 with Selenium

Injel me 2021. 4. 3. 11:49
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from selenium import webdriver
import codecs
import re
 
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1920x1080')
options.add_argument("disable-gpu")
 
driver = webdriver.Chrome('chromedriver', chrome_options=options)
 
driver.get("https://comic.naver.com/webtoon/weekday.nhn")
driver.implicitly_wait(3)
 
text = driver.page_source
 
driver.quit()
 
= re.compile('[\u3131-\u3163\uac00-\ud7a3]+')
 
text_sp = text.split("\n")
 
file_p = codecs.open("Webtoon_list.txt""w"'UTF-8')
 
for i in text_sp:
    #print("[i] : " + str(i))
    match = p.search(i)
    if str(match) != "None":
        #print("[" + str(count) + "]Webtoon Name : " + match.string)
        if match.string.find('class=\"title\" title='!= -1:
            final_text = match.string.split(">")[1].split("<")[0]
            file_p.writelines(final_text + "\r\n")
 
file_p.close()
cs

파이썬과 셀레니움을 이용해 네이버 웹툰의 이름을 긁어오는 프로그램이다.

셀레니움과 크롬 webdriver.exe를 이용했다.

 

chrome-driver.exe 파일은 Chrome Version : 86.0.4240.75 (86.0.X)에서 작동한다.

크롬 드라이버 파일과 크롬 버전이 호환이 되는 버전이어야 크롬 드라이버 프로그램을 사용 할 수 있다.