python - Selenium Webdriver Chrome 在云功能上失败
问题描述
我正在尝试在 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')
解决方案
Cloud Functions 运行时中当前不提供 Headless Chrome。
如果您有能力为您的 Cloud Function 切换到 Node.js 运行时,您可以使用puppeteer
其中包括无头 Chrome,但 Python 没有等价物。
另一种选择是使用 Cloud Run 而不是 Cloud Functions。见这里的例子:https ://dev.to/di/using-headless-chrome-with-cloud-run-3fdp
推荐阅读
- regex - 正则表达式查找和修复 LF lineEndings 到 CRLF
- react-native - 如何在 Detox 中调整视图的可见性阈值
- python - 单击“播放”时如何清除我的游戏屏幕并移动到新场景
- windows - 在 Windows 上根据给定优先级获取互斥锁
- regex - 使用气体的 Google RE2 正则表达式
- android - 带有 Switch Cases 的 Android ViewModel 不起作用?
- apache-flink - 停止作业而不是重试 Apache Flink 中的特定异常
- android - 默认情况下,Google Nearby 无法在 Android Things 上运行
- css - 如何根据用户的选择动态更改较少的变量颜色主题
- android - 是否可以在所有应用程序的后台运行语音识别