python使用selenium获取请求头(Request Headers)
import json
from selenium import webdriver
caps = {
'browserName': 'chrome',
'loggingPrefs': {
'browser': 'ALL',
'driver': 'ALL',
'performance': 'ALL',
},
'goog:chromeOptions': {
'perfLoggingPrefs': {
'enableNetwork': True,
},
'w3c': False,
},
}
driver = webdriver.Chrome(desired_capabilities=caps)
driver.get('https://www.baidu.com')
for log in driver.get_log('performance'):
if all(i in str(json.loads(log['message'])['message']['params']) for i in ('requestHeaders', 'User-Agent')):
print(json.loads(log['message'])['message']['params']['response']['requestHeaders'])
driver.close()
selenium获取请求参数,在selenium加入下面两句,只能获取Post请求
import logging
logging.basicConfig(level = logging.DEBUG)