LoginSignup
0
1

More than 3 years have passed since last update.

HerokuにてSelenium利用時にChrome has crashedのエラー

Posted at

わりとレアケースだとおもうけど、stackoverflowの同様の質問欄みても解決できなかったので念の為投稿

  File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /app/.apt/usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

結論: For文内でWebブラウザ取得すると、5回目くらいでおきるよ!!

Before
```
for 商品 in 商品リスト:
browser = セレニウムからWEBブラウザ取得()
browser.get('URL')

def セレニウムからWEBブラウザ取得():
options = Options()
options.add_argument('--no-sandbox')
options.add_argument("--headless")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--window-size=1920,1080")
browser = webdriver.Chrome(ChromeDriverManager().install(), options=options)
return browser
```

After
```
browser = セレニウムからWEBブラウザ取得()
for 商品 in 商品リスト:
browser.get('URL')

def セレニウムからWEBブラウザ取得():
options = Options()
options.add_argument('--no-sandbox')
options.add_argument("--headless")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--window-size=1920,1080")
browser = webdriver.Chrome(ChromeDriverManager().install(), options=options)
return browser
```

これだけ。
まぁAfterのほうが効率的だし。
なんか5回以上Borwserを呼び出したらだめだよ!みたいな制約あるんかな?
ローカルだと起きない。Heroku上だと起きる。

0
1
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
1