在CoLab for Selenium中安装和运行浏览器 [英] Installing and running browser in colab for selenium

查看:33
本文介绍了在CoLab for Selenium中安装和运行浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以用Google CoLab做Selenium模块,但是在使用Selenium之前,CoLab虚拟机里应该有浏览器,所以我用命令成功地在CoLab里安装了Firefox

!apt-get update
!apt install firefox

但当我尝试使用命令运行Firefox时

!firefox

它引发错误

src/tcmalloc.cc:283]尝试释放无效指针0x7f4e34915040 将对Abort()的调用重定向到mozalloc_Abort

其他浏览器(如Chrome-Browser和Chrome)也会出现同样的问题。
我甚至试过

import webbrowser
webbrowser.get('firefox').open('https://www.youtube.com')

但它抛出一个错误,说明

找不到浏览器位置

因此,总的来说,我需要运行浏览器时出现此错误的解决方案

尝试释放无效指针0x7f4e34915040

推荐答案

我无法安装Firefox。但如果你能用Chrome。以下是代码。

# install chromium, its driver, and selenium
!apt install chromium-chromedriver
!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.website.com")
print(wd.page_source)  # results
# divs = wd.find_elements_by_css_selector('div')

这篇关于在CoLab for Selenium中安装和运行浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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