Python如何使用seleniumwire接管Chrome查看控制台中参数
更新时间:2025年01月20日 14:23:19 作者:NUZGNAW
文章介绍了如何使用Python的seleniumwire库来接管Chrome浏览器,并通过控制台查看接口参数,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧
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控制台内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
python使用Windows的wmic命令监控文件运行状况,如有异常发送邮件报警
这篇文章主要介绍了python使用Windows的wmic命令监控文件运行状况,如有异常发送邮件报警的示例,帮助大家更好的理解和使用python,感兴趣的朋友可以了解下2021-01-01
Python学习笔记整理3之输入输出、python eval函数
这篇文章主要介绍了Python学习笔记整理3之输入输出、python eval函数的相关资料,需要的朋友可以参考下2015-12-12


最新评论