본문 바로가기
파이썬

selenium 사용하기 - 파이썬

by zgabriel 2024. 7. 18.
728x90

from selenium import webdriver

from selenium.webdriver.chrome.options import Options

import subprocess

from webdriver_manager.chrome import ChromeDriverManager

from selenium.webdriver.chrome.service import Service

from selenium.webdriver.common.by import By

subprocess.Popen(r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\chromeCookie"')

option = Options()

option.add_experimental_option("debuggerAddress", "127.0.0.1:9222")

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=option)

driver.maximize_window()

driver.get(url)

#ID 값으로 가져오기

content = driver.find_element(By.ID, "content")

#텍스트 값 가져오기

content = content.text

#HTML 값 가져오기

content = content.get_attribute('innerHTML')

 

 

반응형