简体   繁体   English

如何使用 Python 访问 Chrome Devtools 网络选项卡中的值?

[英]How to access values in the Chrome Devtools network tab using Python?

Is there a way to access values from the Network tab?有没有办法从“网络”选项卡访问值? Like for example everything under the Name column?例如,名称列下的所有内容? Im using Selenium and am interested in monitoring the Network tab.我正在使用 Selenium,并且对监控“网络”选项卡感兴趣。 Thanks谢谢

In C# I'm using the following way:在 C# 中,我使用以下方式:

Initializing driver:初始化驱动:

            var perfLogPrefs = new ChromePerformanceLoggingPreferences();
        perfLogPrefs.AddTracingCategories(new string[] { "devtools.network", "devtools.timeline" });
        options.PerformanceLoggingPreferences = perfLogPrefs;
        options.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
        options.SetLoggingPreference("performance", LogLevel.All);


        driver = new ChromeDriver(
            ConfigManager.ChromeDriverPath, options);
        ScenarioDefinitions.PathToGoogleCustomProfile = string.Empty;

Getting data from the logs:从日志中获取数据:

var data = driver.Manage().Logs.GetLog("performance");

As a result - you would get a huge amount of json files with all the data.结果 - 您将获得包含所有数据的大量 json 文件。 Translating this code from C# to Python, along with parsing the data you need from json shouldn't be that hard.将此代码从 C# 转换为 Python,以及从 json 解析您需要的数据不应该那么难。 Hope it helps.希望能帮助到你。

Best Regards, Vitali.最好的问候,维塔利。

I did it in Python using Selenium我使用 Selenium 在 Python 中做到了

https://stackoverflow.com/a/68363046/8491363 https://stackoverflow.com/a/68363046/8491363

The key is setting the performance log.关键是设置性能日志。

From Selenium 4.0 onward, the library officially support accessing Chrome devtool info so you can also use that instead.从 Selenium 4.0 开始,该库正式支持访问 Chrome 开发工具信息,因此您也可以使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 python 在 chrome 开发人员工具中访问网络选项卡 - How to access network tab in chrome developer tools using python Chrome Devtools 网络 Selenium python - Chrome Devtools Network Selenium python 我可以使用 python 访问谷歌浏览器开发者工具的网络选项卡吗? - can I access to network tab of google chrome developer tools with python? 如何使用 Selenium python 在 google Chrome 中打开 DevTools? - How do I open the DevTools in google Chrome using Selenium python? Selenium 3 python:为 Chrome DevTools 网络事件添加侦听器 - Selenium 3 python: add listener for Chrome DevTools network event 使用来自 Python 的远程 chrome devtools - Using remote chrome devtools from Python 如何使用 Chrome DevTools 协议访问 Netwrok 响应区域? - How get access to Netwrok response area with Chrome DevTools Protocol? Chrome - 在网络上自动打开 devtools 并保存日志 - Chrome - Automatically open devtools on network and perserve log 如何使用Selenium,Chrome驱动程序和Python关闭新建的标签页 - How to close newly constructed tab using selenium, chrome driver and python 如何从 Python 中的网络选项卡读取? - How to read from the network tab in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM