发布时间:2024-01-04 10:00
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()
import logging
logging.basicConfig(level = logging.DEBUG)