python

关注公众号 jb51net

关闭
首页 > 脚本专栏 > python > Python seleniumwire控制台

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

作者: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控制台内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文