How to get browser network logs using python selenium(如何使用 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 获取浏览器网络日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 python selenium 获取浏览器网络日志


基础教程推荐
- 求两个直方图的卷积 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 包装空间模型 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01