gpt4 book ai didi

python - 我们如何在 colab.research.google.com 中使用 Selenium Webdriver?

转载 作者:行者123 更新时间:2023-12-04 16:57:40 26 4
gpt4 key购买 nike

我想在 colab.research.google.com 中使用 Chrome 的 Selenium Webdriver 进行快速处理。我能够使用 !pip install selenium 安装 Selenium但是 chrome 的 webdriver 需要一个 webdriverChrome.exe 的路径。我应该如何使用它?

P.S.- colab.research.google.com 是一个在线平台,为与深度学习相关的快速计算问题提供 GPU。请避免使用 webdriver.Chrome(path) 等解决方案。

最佳答案

您可以通过安装 Chromium webdriver 并调整一些选项来做到这一点,这样它就不会在 google colab 中崩溃:

!pip install selenium
!apt-get update # to update ubuntu to correctly run apt install
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
import sys
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
wd.get("https://www.webite-url.com")

关于python - 我们如何在 colab.research.google.com 中使用 Selenium Webdriver?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51046454/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com