我需要使用Selenium Chrome驱动程序和browsermob代理获取POST请求的响应正文内容。目前,尽管我可以在浏览器网络流量中看到响应,但是当我读取它时,此内容未包含在我的文件HAR输出中。我该如何做才能捕获响应流量?(对不起,这是编程新手,看不到有关BMP的大量python文档)
server.start()
代理= server.create_proxy()
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(“-proxy-server = {0}”。format(proxy.proxy))
驱动程序= webdriver.Chrome(executable_path =“ chromedriver.exe”,chrome_options = chrome_options)
proxy.new_har(“ req”,options = {'captureHeaders':True,'captureContent':True})
driver.get('https://www.example.com/something')
result_har = json.dumps(proxy.har,sure_ascii = False)
使用open(“ haroutput.har”,“ w”)作为harfile:
harfile.write(result_har)
server.stop()
driver.quit()