无法在google-cloud-run上运行Selenium chrome驱动程序

时间:2019-11-09 15:16:51

标签: python selenium selenium-webdriver selenium-chromedriver google-cloud-run

我有一个运行有效的selenium chrome驱动程序脚本的docker容器,但是当将同一映像部署到Google Cloud Run时,会遇到以下错误。

webdriver.Chrome('/home/vmagent/app/chromedriver', chrome_options=self.options) File "/env/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__ desired_capabilities=desired_capabilities) File "/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ self.start_session(capabilities, browser_profile) File "/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/env/lib/python3.7/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: DevToolsActivePort file doesn't exist

这是我用来验证代码在本地运行docker映像的过程。

docker run -it <image_id> /bin/bash

root@e991d8ec09a7:/home/vmagent/app# python


>>> from scaper import Scrape
>>> import asyncio
>>> asyncio.run(Scrape().start())
Scrape has complete -- Entries: 268
>>>

我想知道是否甚至可以在Cloud Run上运行chromedriver,以及什么限制可能导致chromedriver失败。我已经在App Engine上运行了这段代码,但是我希望将所有内容移植到Cloud Run。

这是我用来生成Selenium Web驱动程序的代码。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
browser = webdriver.Chrome('/home/vmagent/app/chromedriver', options=options)

在这里您可以看到chromedriver支持我的Chrome版本

root@2e53a4a78121:/home/vmagent/app# google-chrome --version
Google Chrome 76.0.3809.87
root@2e53a4a78121:/home/vmagent/app# ./chromedriver --version
ChromeDriver 76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-refs/branch-heads/3809@{#864})

selenium==3.141.0

关于我的Cloud Run实例为什么在运行Selenium Webdriver时遇到问题的任何想法?

0 个答案:

没有答案