【发布时间】:2021-10-02 08:18:43
【问题描述】:
我正在尝试在网站上抓取一些内容。为了获得网站上的动态内容,我求助于 selenium。但是当我尝试使用 headless Chrome 时,每次打开页面时终端都会输出以下警告/错误消息。
DevTools listening on ws://127.0.0.1:9234/devtools/browser/3b04bcfa-0f81-4131-813f-9db6f63711fa
[1002/145548.271:ERROR:gpu_init.cc(453)] Passthrough is not supported, GL is swiftshader, ANGLE is
[1002/145548.391:ERROR:command_buffer_proxy_impl.cc(125)] ContextResult::kTransientFailure: Failed to send GpuControl.Cr
eateCommandBuffer.
[1002/145549.272:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'interest-cohort'.", sour
ce: (0)
此外,当我尝试在 Google Colab 中进行抓取时,结果似乎并不好,甚至不稳定。那就是我连续尝试了,抓取内容的长度也不一样。当我使用 non-headless 将相同的代码在本地运行时,Chrome 似乎更好。设置如下。
from selenium import webdriver
from bs4 import BeautifulSoup
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=options)
在我在 Google Colab 中跑步之前。我运行社区中提到的以下命令。
!apt update
!apt install chromium-chromedriver
!pip install selenium
系统
OS: windows 10 + python 3.7 + Chrome 93.0.x + selenium 1.26.6
【问题讨论】:
-
指定无头时为什么要调用 maximise_window?
-
@BrutusForcus 感谢您的回复。当我尝试 non-headless Chrome 时,我首先设置它以最大化我页面的加载内容。抱歉,当我转向 headless 时忘记删除它。我删除了它,但问题仍然存在。
标签: python selenium google-chrome selenium-webdriver