首页 > 解决方案 > 在 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

我怎样才能解决这个问题?

标签: pythonseleniumselenium-webdriver

解决方案


您需要 chromedriver 二进制文件如下:

driver = webdriver.Chrome('/usr/local/bin/chromedriver.exe')

根据您的 chrome 版本从以下位置下载您的 chromedriver:

https://chromedriver.storage.googleapis.com/index.html


推荐阅读