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控制台内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论