DevTools使用Selenium和Python在ws://127.0.0.1:57671/devtools/browser/8a586f7c

编程入门 行业动态 更新时间:2024-10-17 07:22:51
本文介绍了DevTools使用Selenium和Python在ws://127.0.0.1:57671/devtools/browser/8a586f7c-5f2c-4d10-8174-7a7bf50e49b5上侦听的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用python +硒来实现Web浏览器自动化,并收到此错误.

I am using python + selenium for web browser automation and getting this error.

DevTools listening on ws://127.0.0.1:57671/devtools/browser/8a586f7c-5f2c-4d10-8174-7a7bf50e49b5 [5096:1196:0909/183254.362:ERROR:mf_helpers.cc(14)] Error in dxva_video_decode_accelerator_win.cc on line 517

当程序到达代码的这一部分时,就会出现问题:-

The problem arises when the program reaches this part of code:-

def send_comments(driver): add_comments = driver.find_elements_by_class_name('add') comments = driver.find_elements_by_xpath("//form[@class='addCommentexpand']//textarea[contains(@placeholder,'Add a comment')]") submit_comments = driver.find_elements_by_xpath("//button[text()='Comment']") i = 0 for add, comment, submit in zip(add_comments, comments, submit_comments): print("comment begins") add.click() print("+add comment clicked") comment.click() print("comment textbox clicked") comment.send_comments("Amazing Art") print("text typed") submit.click() print("comment submited") i += 1 if i > 5: driver.close() send_comments(driver)

它也没有登录控制台.谁能说出问题所在吗?

Its also not logging in console. Can anyone tell whats the problem?

推荐答案

DevTools在ws://127.0.0.1:9222/devtools/browser/上监听

@AndreaCardaci在文档 在单独的上下文中加载URL 提到在无头模式下使用 Google Chrome

通常的示例代码每次都在单独的上下文中的新的一次性选项卡中运行(认为它是隐身配置文件).

The usual example code is run in a new disposable tab in a separated context (think of it as incognito profiles) each time.

为了从Chrome 62开始获取浏览器版本,浏览器目标URL是在运行时生成的,可以通过 /json/version 端点获取并回退到 /devtools/browser 如果不存在.

As inorder to fetch the browser version since Chrome 62 the browser target URL is generated at runtime and can be obtained via the /json/version endpoint and fallback to /devtools/browser if not present.

以下是相关代码:

const CDP = require('chrome-remote-interface'); async function doInNewContext(action) { // fetch the browser version (since Chrome 62 the browser target URL is // generated at runtime and can be obtained via the '/json/version' // endpoint, fallback to '/devtools/browser' if not present) const {webSocketDebuggerUrl} = await CDP.Version(); // connect to the DevTools special target const browser = await CDP({ target: webSocketDebuggerUrl || 'ws://localhost:9222/devtools/browser' }); // create a new context const {Target} = browser; const {browserContextId} = await Target.createBrowserContext(); const {targetId} = await Target.createTarget({ url: 'about:blank', browserContextId }); // connct to the new context const client = await CDP({target: targetId}); // perform user actions on it try { await action(client); } finally { // cleanup await Target.closeTarget({targetId}); await browser.close(); } } // this basically is the usual example async function example(client) { // extract domains const {Network, Page} = client; // setup handlers Network.requestWillBeSent((params) => { console.log(params.request.url); }); // enable events then start! await Promise.all([Network.enable(), Page.enable()]); await Page.navigate({url: 'github'}); await Page.loadEventFired(); } doInNewContext(example);

此外,根据获得浏览器目标URL(ws://以编程方式 localhost:9222/devtools/browser/...),可以在 webSocketDebuggerUrl 字段中的127.0.0.1:9222/json/version上使用该端点.因此,或者,如果您使用选项--remote-debugging-port=0启动chrome,则将端口和端点都写入浏览器配置文件文件夹中的 DevToolsAcivePort 文件中

Moreover as per Obtain the browser target URL (ws://localhost:9222/devtools/browser/...) programmatically the endpoint is available over 127.0.0.1:9222/json/version in a webSocketDebuggerUrl field. So alternatively, if you are starting chrome with the option --remote-debugging-port=0, both port and endpoint are written to the DevToolsAcivePort file in browser profile folder.

此错误不会影响您的@Test,您暂时可以忽略该错误.

This error doesn't impact your @Test and you can ignore the error for the time being.

更多推荐

DevTools使用Selenium和Python在ws://127.0.0.1:57671/devtools/browser/8a586f7c

本文发布于:2023-11-15 22:31:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598536.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ws   Python   DevTools   Selenium   browser

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!