【问题标题】:Selenium Webdriver Chrome Fails on Cloud FunctionSelenium Webdriver Chrome 在云功能上失败
【发布时间】:2020-02-17 16:38:02
【问题描述】:

我正在尝试在 Cloud Function 上使用 selenium webdriver chrome 运行一个简单的代码。我收到以下错误

消息:“chromedriver”可执行文件需要在 PATH 中。请看https://sites.google.com/a/chromium.org/chromedriver/home

如何在 Cloud Function 中指定 chromedriver 可执行文件?

下面是我的代码

from selenium import webdriver
import time
def test_webdriver(event=None, context=None):
    driver = webdriver.Chrome()
    driver.get('http://www.google.com/');
    time.sleep(5)
    search_box = driver.find_element_by_name('q')

【问题讨论】:

    标签: python google-cloud-platform google-cloud-functions selenium-chromedriver


    【解决方案1】:

    Headless Chrome 目前在 Cloud Functions 运行时中不可用。

    如果您能够为 Cloud Function 切换到 Node.js 运行时,则可以使用 puppeteer,其中包括无头 Chrome,但 Python 没有等效项。

    另一种选择是使用 Cloud Run 而不是 Cloud Functions。示例见此处:https://dev.to/di/using-headless-chrome-with-cloud-run-3fdp

    【讨论】:

    • Pyppeteer 不是等效的吗? pypi.org/project/pyppeteer
    • 不幸的是,pyppeteer 目前无法在 Cloud Functions Python 运行时上运行。
    猜你喜欢
    • 1970-01-01
    • 2019-10-25
    • 2020-10-19
    • 1970-01-01
    • 1970-01-01
    • 2014-08-08
    • 2013-01-16
    • 2021-08-09
    • 2022-09-01
    相关资源
    最近更新 更多