개발/Python
Python crawling 기본 설정
LukeHan1128
2022. 2. 14. 20:00
반응형
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import chromedriver_autoinstaller
import subprocess
driver_path = 'C://webdriver/chromedriver.exe'
chrome_path = 'C://Program Files/Google/Chrome/Application/chrome.exe'
chrome_temp_path = 'C://chrometemp'
# set ChromeDriver
for_debug = chrome_path + ' --remote-debugging-port=9222 --user-data-dir="' + chrome_temp_path + '"'
subprocess.Popen(for_debug) # 디버거 크롬 구동
def connection():
print('[connection]')
option = Options()
option.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
chrome_ver = chromedriver_autoinstaller.get_chrome_version().split('.')[0]
try:
driver = webdriver.Chrome(driver_path, options=option)
except:
chromedriver_autoinstaller.install(True)
driver = webdriver.Chrome(driver_path, options=option)
driver.implicitly_wait(1)
return driver
def main():
driver = connection()
driver.get('https://naver.com')
main()
Python Crawling 을 위한 기본 설정 정보
해당 설정을 적용하여 구동하면 이전 Crawling 시 정보가 유지된다.
초기화가 필요한 경우 chrome_temp_path 를 삭제한다.
반응형