相关疑难解决方法(0)

使用Headless Chrome Webdriver运行Selenium

所以我正在尝试一些硒处理方法,我真的希望它能很快。

所以我的想法是,使用无头的chrome运行它可以使我的脚本更快。

首先,该假设是正确的,还是如果我使用无头驱动程序运行脚本并不重要?

无论如何,我仍然希望它能够正常运行,但是我不知何故,我尝试了不同的方法,并且大多数人建议它可以如十月更新中所说的那样工作

如何配置ChromeDriver通过Selenium以无头模式启动Chrome浏览器?

但是当我尝试这样做时,我得到了奇怪的控制台输出,但它似乎仍然不起作用。

任何小费表示赞赏。

python selenium google-chrome selenium-chromedriver google-chrome-headless

13
推荐指数
4
解决办法
3万
查看次数

在执行一段时间后,Selenium 为所有网站提供“从渲染器接收消息超时”

我有一个应用程序,我需要一个长时间运行的Selenium Web 驱动程序实例(我在无头模式下使用Chrome 驱动程序 83.0.4103.39)。基本上,该应用程序不断从队列中提取 url-data,并将提取的 url 提供给 Selenium,Selenium 应该在网站上执行一些分析。许多这些网站可能已关闭、无法访问或损坏,因此我将页面加载超时设置为 10 秒,以避免 Selenium 永远等待页面加载。
我在这里遇到的问题是,经过一些执行时间(假设 10 分钟)Selenium 开始给出Timed out receiving message from renderer每个 url 的错误。最初它工作正常,它可以正确打开好的网站并在坏网站上超时(网站无法加载),但一段时间后它开始对所有内容超时,即使是应该正确打开的网站(我已经检查过,它们在 Chrome 浏览器上正确打开)。我很难调试这个问题,因为应用程序中的每个异常都被正确捕获。我也注意到这个问题只发生在headless模式中。

  • 更新 *
    在网站分析期间,我还需要考虑 iframe(仅顶级),因此我还添加了一个逻辑来将驱动程序上下文切换到主页中的每个 iframe 并提取相关的 html。

这是应用程序的简化版本:

import traceback
from time import sleep
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

width = 1024
height = 768

chrome_options = Options()
chrome_options.page_load_strategy …
Run Code Online (Sandbox Code Playgroud)

python iframe selenium renderer selenium-chromedriver

7
推荐指数
1
解决办法
6065
查看次数

selenium.common.exceptions.WebDriverException:消息:未知错误:Chromium 浏览器和 Selenium Python 中不存在 DevToolsActivePort 文件

我想通过铬运行硒。我写了这段代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--disable-gpu")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
options.binary_location = "/snap/bin/chromium"
driver = webdriver.Chrome(chrome_options=options)
Run Code Online (Sandbox Code Playgroud)

但这段代码会抛出一个错误:

selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist
Stacktrace:
#0 0x55efd7355a23 <unknown>
#1 0x55efd6e20e18 <unknown>
#2 0x55efd6e46e12 <unknown>
Run Code Online (Sandbox Code Playgroud)

正确版本的 chromedriver 位于 usr/bin 中。我究竟做错了什么?

python chromium selenium-chromedriver selenium-webdriver selenium-webdriver-python

7
推荐指数
2
解决办法
4万
查看次数

错误:gpu_process_transport_factory.cc(1007) - 失去用户界面共享上下文:在无头模式下通过ChromeDriver初始化Chrome浏览器

当我尝试在3台计算机中的2台上运行代码时出现此错误:

[0502/155335.565:ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context.
Run Code Online (Sandbox Code Playgroud)

这是代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=1920x1080")

chrome_driver = os.getcwd() + "\\chromedriver.exe"
print "chrome driver:" + chrome_driver

driver = webdriver.Chrome(chrome_options=chrome_options, 
executable_path=chrome_driver)

driver.get("http://www.google.com")

luck_button = driver.find_element_by_css_selector("[name=btnI")
luck_button.click()

driver.get_screenshot_as_file("capture.png")
Run Code Online (Sandbox Code Playgroud)

现在我已经检查了所有系统,它们运行的​​是Windows 10 64位,谷歌浏览器64位版本:66.0.3359.139,python 2.7 32位,chromedriver.exe 32位,pycharm 2018.1.1

有趣的是,如果我在没有无头选项的情况下运行它,那么一切正常.弹出浏览器,I'm feeling lucky按下按钮,然后拍摄屏幕截图.只有当我添加无头位时才会发生此错误.

我不确定在其他系统运行相同软件的情况下,1系统可能有什么不同.

python selenium selenium-chromedriver selenium-webdriver google-chrome-headless

6
推荐指数
1
解决办法
1万
查看次数

在无头模式下使用 ChromeDriver 和 Chrome 以及 --disable-gpu 和 --user-data-dir 参数时,GPU 进程崩溃了 x 次错误

我正在使用硒来打开一个网站。具体来说:

https://storage.googleapis.com/tfjs-models/demos/posenet/camera.html
Run Code Online (Sandbox Code Playgroud)

但是当它使用无头模式打开它时,它显示以下错误:

[0513/155639.694:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 1 time(s)

DevTools listening on ws://127.0.0.1:6573/devtools/browser/58f34b20-1a05-4bf0-8e64-1b5a5028b1f6
[0513/155639.710:ERROR:cache_util_win.cc(21)] Unable to move the cache: Access is denied. (0x5)
[0513/155639.710:ERROR:cache_util.cc(138)] Unable to move cache folder C:/Users/Tazim Fatima/AppData/Local/Google/Chrome/User Data\Default\GPUCache to C:/Users/Tazim Fatima/AppData/Local/Google/Chrome/User Data\Default\old_GPUCache_000
[0513/155639.710:ERROR:disk_cache.cc(184)] Unable to create cache
[0513/155639.710:ERROR:shader_disk_cache.cc(606)] Shader Cache Creation failed: -2
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 2 time(s)
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 3 time(s)
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 4 time(s)
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has …
Run Code Online (Sandbox Code Playgroud)

python selenium selenium-chromedriver selenium-webdriver google-chrome-headless

6
推荐指数
1
解决办法
2万
查看次数