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 获取浏览器网络日志
基础教程推荐
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
