gpt4 book ai didi

java - BrowserMobProxy 不会捕获 har 文件中的任何条目

转载 作者:行者123 更新时间:2023-12-02 00:39:09 26 4
gpt4 key购买 nike

尝试在某些测试页面 localhost:8000 上捕获 http header ,而 HAR 文件在 entry 部分中似乎不包含任何内容。

我的代码:

            BrowserMobProxyServer proxy = new BrowserMobProxyServer();

proxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
seleniumProxy.setSslProxy("trustAllSSLCertificates");
try {
String hostIp = Inet4Address.getLocalHost().getHostAddress();
seleniumProxy.setHttpProxy(hostIp + ":" + proxy.getPort());
seleniumProxy.setSslProxy(hostIp + ":" + proxy.getPort());
} catch (UnknownHostException e) {
e.printStackTrace();
}
WebDriverManager.chromedriver().setup();
DesiredCapabilities seleniumCapabilities = new DesiredCapabilities();
seleniumCapabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
seleniumCapabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);

ChromeOptions options = new ChromeOptions();
options.addArguments("--ignore-certificate-errors");
options.addArguments("--user-data-dir=temp");
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.merge(seleniumCapabilities);
webDriver = new ChromeDriver();
proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);

proxy.setHarCaptureTypes(CaptureType.REQUEST_HEADERS, CaptureType.RESPONSE_HEADERS);
proxy.enableHarCaptureTypes(CaptureType.REQUEST_HEADERS,CaptureType.RESPONSE_HEADERS);
proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
driver.get("http://localhost:8000")
proxy.newHar("Test");

http://localhost:8000打开时,我可以在console>networks选项卡中看到8个项目然而har文件是:

{"log":{"version":"1.2","creator":{"name":"BrowserMob Proxy","version":"2.1.4","comment":""},"pages":[{"id":"Test","startedDateTime":"2019-09-16T11:06:02.020Z","title":"Test","pageTimings":{"comment":""},"comment":""}],"entries":[],"comment":""}}

挖掘了无数的页面,看起来所有其他人都只遇到了 http 和 headless 的问题。

最佳答案

找到了解决方案。更改 String hostIp = "localhost"确实解决了该问题。

关于java - BrowserMobProxy 不会捕获 har 文件中的任何条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57955764/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com