I have written this code in python,using undetected_chromedriver and browsermobproxy
from selenium.webdriver.chrome.options import Options
import undetected_chromedriver as uc
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from browsermobproxy import Server
from selenium.webdriver.chrome.service import Service
if __name__ == "__main__":
server = Server(
r"E:\YUNLIANG\yl.sc.addons\sourcecode\trunk\yl.sc.addons.tools\browsermob-proxy-2.1.4\bin\browsermob-proxy")
server.start()
proxy = server.create_proxy({'trustAllServers': True})
print(proxy.proxy)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("user-data-dir=D:\SeleniumChrome")
chrome_options.add_argument(f'--proxy-server={proxy.proxy}')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_driver = uc.Chrome(options=chrome_options, headless=True,
use_subprocess=False, version_main=121, port=9222)
# 访问页面同时监听结果
proxy.new_har("my_title",options={
'captureContent': True,
'captureHeaders': True,
'captureBinaryContent': True
})
url = "https://www.inter.it/it"
chrome_driver.get(url=url)
time.sleep(5)
result = proxy.har
print("----------------------------------------------------------------------------------------------------")
print(result)
But when I try to validate through HAR Analyzer, it return a empty entries array
localhost:8081
----------------------------------------------------------------------------------------------------
{'log': {'version': '1.2', 'creator': {'name': 'BrowserMob Proxy', 'version': '2.1.4', 'comment': ''}, 'pages': [{'id': '666', 'startedDateTime': '2024-02-28T15:47:03.286+08:00', 'title': '666', 'pageTimings': {'comment': ''}, 'comment': ''}], 'entries': [], 'comment': ''}}
I hope to be able to intercept the website's ajax request and the server's response to the request