【问题标题】:Unable to run chromedriver using Python & selenium in cloud9 & aws无法在 cloud9 和 aws 中使用 Python 和 selenium 运行 chromedriver
【发布时间】:2019-06-27 09:10:54
【问题描述】:

我尝试在 cloud9 和 aws lambda 中使用 python 和 selenium 执行抓取,但是,chromedriver (路径)似乎存在一些问题并且它没有运行。 我的代码是;

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

def lambda_handler(event, context):
    options = Options()
    options.add_argument('--headless')
    path = '/home/ec2-user/environment/testHW/chromedriver.exe'
    url = 'https://www.google.com'
    driver = webdriver.Chrome(executable_path=path, chrome_options=options)
    driver.get(url)
    driver.save_screenshot('screenshot.png')

我已经把chromedriver放在了相应的位置。 但是,我收到如下错误消息;

Response
    {
        "errorMessage": "Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home\n",
        "errorType": "WebDriverException",
        "stackTrace": [
            [
                "/var/task/testHW/lambda_function.py",
                11,
                "lambda_handler",
                "driver = webdriver.Chrome(executable_path=path, chrome_options=options)"
            ],
            [
                "/var/task/selenium/webdriver/chrome/webdriver.py",
                73,
                "__init__",
                "self.service.start()"
            ],
            [
                "/var/task/selenium/webdriver/common/service.py",
                83,
                "start",
                "os.path.basename(self.path), self.start_error_message)"
            ]
        ]
    }

    Function Logs
    Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
    : WebDriverException
    Traceback (most recent call last):
      File "/var/task/testHW/lambda_function.py", line 11, in lambda_handler
        driver = webdriver.Chrome(executable_path=path, chrome_options=options)
      File "/var/task/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
        self.service.start()
      File "/var/task/selenium/webdriver/common/service.py", line 83, in start
        os.path.basename(self.path), self.start_error_message)
    selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

    Request ID
    82bcf27f-255e-431d-ae13-6a0efba8d69a

谁能指出问题出在哪里?

【问题讨论】:

    标签: python amazon-web-services selenium aws-cloud9


    【解决方案1】:

    消息:“chromedriver.exe”可执行文件需要在 PATH 中。这个错误意味着它需要一个可执行路径

    从您的目录结构看来,您使用的是 linux base os。去这个link 并下载 chromedriver for linux。

    打开chromedriver所在的目录,现在打开终端并输入以下命令,允许chromedriver的可执行权限。

    sudo chmod +x chromedriver
    

    我希望它会起作用。

    【讨论】:

    • 拉贾特,谢谢您的建议!我认为这将解决问题。
    • Rajat,我相信你的建议解决了部分问题,但似乎代码仍然给我同样的错误......
    • 您使用的是哪个操作系统?
    • 如果您在 cloud9 中使用 windows,请确保您使用的是 windows 版本的 chromedriver。请更正此路径 = '/home/ec2-user/environment/testHW/chromedriver.exe' 否则对于 linux 路径 = '/home/ec2-user/environment/testHW/chromedriver.exe' 是正确的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 2014-03-23
    • 1970-01-01
    • 2021-10-04
    • 1970-01-01
    相关资源
    最近更新 更多