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

查看:454
本文介绍了我们如何在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).

推荐答案

您可以通过安装Chrome Web驱动程序并调整一些选项以使其在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天全站免登陆