我使用python wrapper为browsermob proxy,我需要修改服务器响应。但我无法弄清楚我能做到这一点。任何人都可以给我一个有效的代码示例吗?Browsermob代理 - 如何使用response_interceptor修改响应?
文档说我可以给一个JavaScript代码,但它不为我工作:
server = Server(path=SCRIPT_DIR+"/browsermob-proxy/bin/browsermob-proxy", options={"port": 8888})
server.start()
proxy = server.create_proxy()
proxy.response_interceptor('contents.setTextContents("<html><body>Response successfully intercepted</body></html>")')
fp = webdriver.FirefoxProfile()
browser = webdriver.Firefox(firefox_profile=fp, proxy=proxy)
browser.get("http://example.com")
谢谢!