如何使用 python selenium 获取浏览器网络日志 [英] How to get browser network logs using python selenium

查看:166
本文介绍了如何使用 python selenium 获取浏览器网络日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 selenium 获取浏览器网络日志以调试请求/响应.你能帮我找出一个方法吗.

I'm trying to get browser network logs using selenium to debug request/responses. Could you please help me to find out a way.

我正在使用 selenium 3.14.0 和最新的 Chrome 浏览器.

And I'm using selenium 3.14.0 and latest Chrome browser.

推荐答案

使用python + selenium + firefox

除非必须,否则不要设置代理——为了获得出站 API 请求,我使用了这个答案中的解决方案,但在 python 中:https://stackoverflow.com/a/45859018/14244758

Don't set up a proxy unless you have to- in order to get outbound API requests I used the solution from this answer, but in python: https://stackoverflow.com/a/45859018/14244758

test = driver.execute_script("var performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {}; var network = performance.getEntries() || {}; return network;")

for item in test:
  print(item)

你得到一个字典数组.

这让我可以看到所有的网络请求.我正在使用它从其中一个请求中解析出一个参数,以便我可以使用它来针对 API 发出自己的请求.

This allows me to see all the network requests made. I'm using it to parse out a parameter from one of the requests so that I can use it to make my own requests against the API.

这篇关于如何使用 python selenium 获取浏览器网络日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆