설치
$ brew upgrade chromedriver --cask
$ pip install selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# This is not needed if chromedriver is already on your path:
chromedriver_path = "/chrome/driver/path"
options = Options()
options.add_argument("--window-size=1920x1080")
options.add_argument("--verbose")
# options.add_argument("--headless")
driver = webdriver.Chrome(options=options, chromedriver_path=executable_path)
driver.get("<https://www.example.com>")
This opened a visible Chrome window to <https://www.example.com/>
print(driver.find_element_by_css_selector('body').text)
Selenium docs
2. Getting Started — Selenium Python Bindings 2 documentation
열려있는 창으로 작업
$ /Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --user-data-dir="~/ChromeProfile"
$ /Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --user-data-dir="/Users/kbae/Applications/Google Chrome.app/"
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options() ## 옵션 추가를 위한 준비
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222") ## 디버깅 옵션 추가
driver = webdriver.Chrome(options=chrome_options)
함수로 사용 시 꺼지지 않게
from selenium import webdriver
import os
import chromedriver_autoinstaller as AutoChrome
import shutil
def selenium_test():
chrome_ver = AutoChrome.get_chrome_version().split('.')[0]
path = os.path.join(os.getcwd(),chrome_ver)
path = os.path.join(path,'chromedriver.exe')
print(path)
URL = '<https://www.google.co.kr/>'
driver = webdriver.Chrome(str(path))
driver.get(url=URL)