我知道google colab可以用于硒模块,但是在使用硒之前,colab虚拟机中应该有一个浏览器,因此我已经通过使用命令在colab中成功安装了firefox
!apt-get update
!apt install firefox
但是当我尝试使用命令运行firefox
!firefox
它引发错误
src / tcmalloc.cc:283]尝试释放无效的指针0x7f4e34915040 将对abort()的调用重定向到mozalloc_abort
其他浏览器(例如铬浏览器和chrome)也会发生相同的问题。
我什至尝试过
import webbrowser
webbrowser.get('firefox').open('https://www.youtube.com')
但抛出错误
找不到浏览器位置
因此,总的来说,我需要针对运行浏览器时发生的此错误的解决方案
尝试释放无效的指针0x7f4e34915040
答案 0 :(得分:0)
我无法安装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')