【问题标题】:Google Cloud Platform - Deploy a Cloud Function that starts a webdriverGoogle Cloud Platform - 部署一个启动 webdriver 的云函数
【发布时间】:2020-02-01 15:27:12
【问题描述】:

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

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

from selenium import webdriver

def launch_search(request):
    # Starting a webdriver
    driver = webdriver.Chrome()
    return 'Success'

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

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

【问题讨论】:

    标签: python selenium web-scraping google-cloud-platform automation


    【解决方案1】:

    鉴于 Cloud Functions 是无服务器的,您无法控制服务器机器。 您可以使用其他可管理的服务,例如GCEGKE

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      【解决方案3】:

      看起来可以在 Google Cloud Functions 上运行 selenium。如果你对 JavaScript/TypeScript 示例而不是 Python 感到满意,我建议你试试这个模板:https://github.com/ccorcos/gcloud-functions-selenium-boilerplate

      【讨论】:

        猜你喜欢
        • 2023-04-07
        • 2020-10-20
        • 1970-01-01
        • 2020-11-14
        • 2023-03-12
        • 2018-07-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多