LoginSignup
0
0

More than 3 years have passed since last update.

絶対WebDriverを取得するマン

Last updated at Posted at 2021-04-19

スクレイピングするプログラムを走らせてたらなんか止まってたので作った。
プログラムが走っている際にWebDriverを更新する人向け。

from selenium import webdriver

def chrome_driver(options=['--headless']):
    """FileNotFoundErrorがたまに起こったりする人向け。
    エラーが続く場合は無限ループ。
    戻り値はWebDriver(Chrome)"""
    chrome_options = webdriver.ChromeOptions()
    for option in options:
        chrome_options.add_argument(option)
    while True:
        try:
            return webdriver.Chrome(options=chrome_options)
        except Exception as e:
            # 無限ループ注意
            pass
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