LoginSignup
0
0

More than 3 years have passed since last update.

Chromedriverをheadlessで試す

Posted at

試す

いちいちheadlessに移行するために書き足したりコメントアウトするのめんどくさいからコマンドライン引数をとる

import sys
from selenium import webdriver

try:
    sys.argv[2]
    if sys.argv[2] == "headless":
        options = webdriver.ChromeOptions()
        options.add_argument('--headless')
        driver = webdriver.Chrome('./chromedriver', options=options)
    else:
        # chromeを開く
        driver = webdriver.Chrome('./chromedriver')
except:
    # chromeを開く
    driver = webdriver.Chrome('./chromedriver')

これで

$python ~~~.py headless

でheadlessが動く
簡単

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0