相关疑难解决方法(0)

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

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

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

selenium selenium-webdriver google-colaboratory

5
推荐指数
5
解决办法
5741
查看次数

WebDriverException:消息:服务 /content/chromedriver 意外退出。状态代码为:-6 使用 ChromeDriver Google Colab 和 Selenium

我试图使用 Selenium 运行无头 Chrome 浏览器来从网络上抓取内容。我使用 wget 安装了无头 Chrome,然后在我当前的文件夹中解压。

!wget "http://chromedriver.storage.googleapis.com/2.25/chromedriver_linux64.zip"
!unzip chromedriver_linux64.zip
Run Code Online (Sandbox Code Playgroud)

现在当我加载驱动程序时

from selenium.webdriver.chrome.options import Options
import os
# instantiate a chrome options object so you can set the size and headless preference
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=1920x1080")

chrome_driver = os.getcwd() +"/chromedriver"
driver = webdriver.Chrome(chrome_options=chrome_options,executable_path=chrome_driver)
Run Code Online (Sandbox Code Playgroud)

我收到一个错误

WebDriverException                        Traceback (most recent call last)
<ipython-input-67-0aeae0cfd891> in <module>()
----> 1 driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=chrome_driver)
  2 driver.get("https://www.google.com")
  3 lucky_button = driver.find_element_by_css_selector("[name=btnI]")
  4 lucky_button.click()
  5 /usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, chrome_options, service_args, desired_capabilities, service_log_path) …
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome selenium-webdriver google-colaboratory

4
推荐指数
1
解决办法
8078
查看次数

Selenium + Google Colab 错误:“chromedriver”可执行文件需要在 PATH 中

我在此线程中使用@korakot-chaovavanich 提供的代码如何在 Colaboratory Google 上使用 Selenium?. 我真的需要一个解决方案来让它在 Google Colab 上运行。

# install chromium, its driver, and selenium
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium
# set options to be headless, ..
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# open it, go to a website, and get results
wd = webdriver.Chrome('chromedriver',options=options)
wd.get("https://www.google.com")
print(wd.page_source)  # results
Run Code Online (Sandbox Code Playgroud)

我已经在 Google Colab 中进行了测试,但我不知道为什么它无法工作。我试图在 /usr/lib 下查看,但找不到任何“chromium-browser”文件夹。我无法确定 chromedriver 在 Google Colab 中的安装位置。

在 Google Colab 中执行此代码的错误消息:

Reading …
Run Code Online (Sandbox Code Playgroud)

selenium google-colaboratory

4
推荐指数
1
解决办法
5028
查看次数