首页 > 解决方案 > 如何在谷歌 colab 中运行 chrome webdriver?

问题描述

如何在谷歌 colab 中运行 chrome webdriver?

点安装

  1. !pip 安装硒
  2. !apt-获取更新
  3. !apt 安装铬铬驱动程序
  4. !cp /usr/lib/chromium-browser/chromedriver /usr/bin

my sample code

from selenium import webdriver 

options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver', options=options)
url = "https://www.instagram.com/" 

driver.get(url)

我的照片

在此处输入图像描述

当我在 colab 中运行 chrome webdriver 时,

I want to see the execution process with a window.

但是窗户打不开。

我该如何处理?

更新帖子 在此处输入图像描述

更新帖子2 在此处输入图像描述

标签: selenium

解决方案


要查看打开的浏览器等,您应该以常规模式运行浏览器,而当前您正在以无头模式运行。
所以,你不必使用options.add_argument('--headless')


推荐阅读