相关疑难解决方法(0)

使用 Headless Chrome 运行 Selenium 的 AWS Lambda 容器可以在本地运行,但不能在 AWS Lambda 中运行

我目前正在开发一个 Python 程序,它有一个使用无头版本的 Chrome 和 Selenium 来执行重复过程的段。我的目标是在 Lambda 上运行该程序。

整个程序有大约 1GB 的依赖项,因此无法选择使用.zip 存档的标准方法,其中包含我的所有函数代码和依赖项,因为函数和所有层的总解压缩大小不能超过解压后的部署包大小限制为 250 MB。

所以,这就是新的AWS Lambda – Container Image Support(我使用这个链接教程来开发整个实现,所以如果你需要更多信息,请阅读)进来的地方。这允许我打包和部署我的 Lambda 函数作为容器镜像大小高达 10 GB。

我正在使用由运行 Amazon Linux 2 的 AWS 提供的 ECR Public 中托管的基本映像。首先 - 在我的 Dockerfile 中,我:

  • 下载基础镜像。
  • 定义一些全局变量。
  • 复制我的文件。
  • 安装我的 pip 附录
  • 使用 yum 安装一些软件包。

最后 - 我安装了 Chrome(阅读时为 87.0.4280.88)和 Chromedriver(87.0.4280.88)

  • 最后下载安装最新版本的 Chrome 和 Chromedriver

有可能这可能是问题所在,但我非常怀疑这是同一版本 - ChromeDriver 使用与 Chrome 相同的版本号方案

这是我的Dockerfile

# 1) DOWNLOAD BASE IMAGE.
FROM public.ecr.aws/lambda/python:3.8

# …
Run Code Online (Sandbox Code Playgroud)

python selenium chromium docker aws-lambda

9
推荐指数
3
解决办法
3931
查看次数

Chrome无法使用chromedriver2.9在CentOS上启动

环境:chromedriver 2.9,google-chrome-stable 34,python 2.6,CentOS6.4 final x86_64

我按照install-chrome.sh安装google-chrome-stable(不是chrome).它可以从fedoraproject中提取包并安装这些包/opt/google/chrome/lib.我安装了chromedriver2.9关注链接.我可以手动运行google-chrome和chromedriver而不会出错.我安装了硒pip install selenium(硒2.41).Selenium安装到/usr/lib/python2.6/site-packages/.以这种方式安装的Google Chrome似乎不允许以root身份打开.

当我在非root用户的python控制台下运行代码时如下:

>>> from selenium import webdriver
>>> driver = webdriver.Chrome()
Run Code Online (Sandbox Code Playgroud)

它返回错误消息,而不是打开chrome.

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/usr/lib/python2.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 65, in __init__
    keep_alive=True)
  File "/usr/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 72, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 115, in start_session
    'desiredCapabilities': desired_capabilities,
  File "/usr/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 166, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python2.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 164, in check_response
    raise exception_class(message, …
Run Code Online (Sandbox Code Playgroud)

selenium google-chrome centos google-chrome-devtools selenium-chromedriver

7
推荐指数
1
解决办法
3195
查看次数

WebDriverException:消息:未知错误:Chrome 无法启动:在 VPS 上通过 Python 使用 ChromeDriver Chrome 和 Selenium 异常退出

所以我有与这些帖子完全相同的错误

Selenium“Chrome 无法启动:异常退出”错误

未知错误:Chrome 无法启动:异常退出

我尝试了他们推荐的方法,但没有成功。

这是我的代码

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))
display.start()

options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-extensions')
options.add_argument('--headless')
options.add_argument('--disable-gpu')

driver = webdriver.Chrome(chrome_options=options)
driver.get('http://nytimes.com')
print(driver.title)

driver.close()
Run Code Online (Sandbox Code Playgroud)

这是完整的错误消息

Traceback (most recent call last):
  File "seleniumtest.py", line 13, in <module>
    driver = webdriver.Chrome(chrome_options=options)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute …
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome selenium-chromedriver google-chrome-headless

5
推荐指数
1
解决办法
1万
查看次数

从 Ubuntu 中删除 chromedriver

我想更新我按照此说明安装的 chromedriver 版本https://christopher.su/2015/selenium-chromedriver-ubuntu/

为此,我想删除当前版本。我试图通过找到所需的文件夹来做到这一点

哪里有 chromedriver

命令。并使用 rm 从那里删除文件。但

chromedriver -v

仍然给出了旧版本的价值。完全删除当前 chromedriver 的另一种方法是什么?我也尝试只更新这个主题如何在 Ubuntu 上更新 Chromedriver? 但是 chromedriver -v 仍然返回旧版本

ubuntu selenium-chromedriver

5
推荐指数
1
解决办法
6553
查看次数

尝试使用selenium webdriver在linux上启动chrome驱动程序

我试着找到答案而不能,现在我自己问.

我写了简单的测试

from selenium import webdriver

driver = webdriver.Chrome(executable_path=r"/home/tranter/workspace/chromedriver")
driver.get("http://www.python.org")
driver.close()
Run Code Online (Sandbox Code Playgroud)

比我有追溯

> tranter@tranter-VirtualBox:~/workspace$ python testchrome.py Traceback
> (most recent call last): File "testchrome.py", line 6, in <module>
> driver =
> webdriver.Chrome(executable_path=r"/home/tranter/workspace/chromedriver")
> File
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py",
> line 65, in __init__ keep_alive=True) File
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
> line 73, in __init__ self.start_session(desired_capabilities,
> browser_profile) File
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
> line 121, in start_session 'desiredCapabilities':
> desired_capabilities, File
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
> line 173, in execute self.error_handler.check_response(response) File
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py",
> line 166, …
Run Code Online (Sandbox Code Playgroud)

python linux selenium selenium-chromedriver

3
推荐指数
2
解决办法
7842
查看次数