当前位置: 代码网 > it编程>前端脚本>Python > Python如何使用seleniumwire接管Chrome查看控制台中参数

Python如何使用seleniumwire接管Chrome查看控制台中参数

2025年01月21日 Python 我要评论
1、cmd打开控制台,启动谷歌并制定端口号,找不到文件的加环境变量chrome.exe --remote-debugging-port=92222、获取f12控制台中接口参数from selenium

1、cmd打开控制台,启动谷歌并制定端口号,找不到文件的加环境变量

chrome.exe --remote-debugging-port=9222

2、获取f12控制台中接口参数

from selenium.webdriver.chrome.service import service
from seleniumwire import webdriver
chrome_options = webdriver.chromeoptions()
chrome_options.add_experimental_option("debuggeraddress", "127.0.0.1:9222")
chrome_options.set_capability("browsername", 'chrome')
chrome_options.set_capability("goog:chromeoptions", {'perfloggingprefs': {'enablenetwork': true}, 'w3c': false})
chrome_options.set_capability("goog:loggingprefs", {"performance": "all"})
service = service(executable_path='d:\crack-plugin\chromedriver-win64\chromedriver.exe')
driver = webdriver.chrome(service=service, options=chrome_options)
driver.get("https://example.com")
print("已监听到网页,名称为:" + driver.title)
performance_log = driver.get_log('performance')
authorization = none
print(authorization)

3、如果需要获取针对性的参数,比如header中的登录令牌bearer token的话,进行针对性的写法即可

for log in performance_log:
        if "authorization" in log['message']:
            message = json.loads(log['message'])
            if "network.requestwillbesentextrainfo" == message['message']['method']:
                bearer = message['message']['params']['headers']['authorization']
                authorization = bearer
                print("获取到登录令牌:" + bearer)

到此这篇关于python使用seleniumwire接管chrome查看控制台中参数的文章就介绍到这了,更多相关python seleniumwire控制台内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com