我们如何在 colab.research.google.com 中使用 Selenium Webdriver? [英] How can we use Selenium Webdriver in colab.research.google.com?

查看:33
本文介绍了我们如何在 colab.research.google.com 中使用 Selenium Webdriver?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to use Selenium Webdriver of Chrome in colab.research.google.com for fast processing. I was able to install Selenium using !pip install selenium but the webdriver of chrome needs a path to webdriverChrome.exe. How am I suppose to use it?

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

P.S.- colab.research.google.com is an online platform which provides GPU for fast computational problems related to deep learning. Please refrain from solutions such as webdriver.Chrome(path).

推荐答案

您可以通过安装 Chromium webdriver 并调整一些选项使其不会在 google colab 中崩溃来实现:

You can do it by installing the chromium webdriver and adjusting some options such that it does not crash in 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")

这篇关于我们如何在 colab.research.google.com 中使用 Selenium Webdriver?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆