我们如何在colab.research.google.com中使用Selenium Webdriver? [英] How can we use Selenium Webdriver in colab.research.google.com?
问题描述
我想在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屋!