Google Cloud Platform - 部署启动网络驱动程序的云函数

lud*_*aex 6 python selenium automation web-scraping google-cloud-platform

我正在 GCP 上定义一个云函数,用于在 Python 中抓取网站。

我从定义一个简单地打开 webdriver 的函数开始:

from selenium import webdriver

def launch_search(request):
    # Starting a webdriver
    driver = webdriver.Chrome()
    return 'Success'
Run Code Online (Sandbox Code Playgroud)

这个功能不起作用(Error: could not handle the request当我触发它时),可能是因为我的远程机器上没有安装 Chrome 驱动程序。所以:

  • 我该如何安装?
  • 或者我可以使用 Selenium抓取网页,而无需使用网络驱动程序打开页面吗?

Max*_*xim 2

您当前无法使用 Python 运行 Selenium 脚本。目前,公共问题跟踪器中有一个为此开放的功能请求,可以在此处找到。

作为替代方案,您可以将 Node.JS 与 Puppeteer 结合使用。我发现这篇博文详细介绍了一个用例。