python - 在 ec2 实例上使用 python 脚本打开 Chrome 浏览器
问题描述
我正在运行这个 python 脚本来打开我的 chrome 浏览器。我正在使用 selenium 的 ec2 实例上运行我的脚本。我已经在我的实例上安装了 selenium 和所需的包。这是我的脚本
from selenium import webdriver
# The place we will direct our WebDriver to
url = 'http://www.srcmake.com/'
# Creating the WebDriver object using the ChromeDriver
driver = webdriver.Chrome()
# Directing the driver to the defined url
driver.get(url)
但是当我运行这个脚本时,我得到了这个错误
Traceback (most recent call last):
File "main.py", line 7, in <module>
driver = webdriver.Chrome()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127
我怎样才能解决这个问题?
解决方案
您需要 chromedriver 二进制文件如下:
driver = webdriver.Chrome('/usr/local/bin/chromedriver.exe')
根据您的 chrome 版本从以下位置下载您的 chromedriver:
推荐阅读
- c++ - 为什么 do while 循环不会中断?
- postgresql - 将 Debug 配置切换到 Release 会关闭 Devart.Data.PostgreSql 命名空间
- excel - Web 提取代码需要更新,尝试从工作表单元格中添加工作表
- java - Java Swing 表单的 Nullpointerexception
- google-cloud-platform - 部署谷歌云功能需要很长时间
- tsql - 在数据库中搜索选定的表并排列结果?
- flutter - 我如何从颤动的底部创建抽屉标题看起来像这样
- java - 将数组加载到列表中,但它与新内存重复(Java)
- firebase - 未找到合适的运行配置
- c# - 从ini文件向exe传递参数