![](/img/trans.png)
[英]Connect google cloud function 2nd gen to mysql of another project
[英]Google Cloud Function (2nd) + Python Selenium - Chrome failed to start: exited abnormally
我和这篇文章有同样的错误:
WebDriverException:消息:未知错误:Chrome 无法启动:ChromeDriver 异常退出 Chrome 和 Selenium 到 VPS 上的 Python
Howerver 似乎我有不同的问题 - 管理版本并不能解决它。
我正在尝试使用 Google Cloud Functions(基于 Cloud Run 的 2nd tear)来运行 Seleniu。
我的代码只是基本代码:
主要文件:
def hello_world(request):
print("Start")
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from chromedriver_py import binary_path
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
chrome_options = Options()
chrome_options.binary_location=binary_path
chrome_options.add_argument("--remote-debugging-port=9222")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=1920x1080")
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-extensions')
driver = webdriver.Chrome(options=chrome_options,service=Service(ChromeDriverManager().install()))
driver.get("https://www.google.com")
print(driver.title)
driver.close()
print("End")
return "Empty - nothing"
要求.txt:
selenium >= 4.2.0
webdriver-manager >= 3.7.0
chromedriver_py >= 103.0.5060.24
它给出错误:“selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome 无法启动:异常退出”
有人想通了吗?
我发现云函数无法与 Selenium 一起使用的信息: 我可以将 Selenium WebDriver 与 Google 云函数一起使用吗?
但是我将它设置在基于 Cloud Run 的第二代环境中,所以我希望有办法让它工作......
这可能是 6 个月大,但如您所见,您似乎无法在 Cloud Function 中将 Selenium 与 Python 一起使用。但您可以使用 Cloud Run 来完成: https://dev.to/googlecloud/using-headless-chrome -with-cloud-run-3fdp 。 或者,您可以在 Cloud Function 中使用 Node.js 以及 puppeteer package: https://rominirani.com/using-puppeteer-in-google-cloud-functions-809a14856e14 。 我也在尝试做同样的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.