我正在尝试使用selenium捕获https流量,但无法捕获它。Http流量被正确捕获,但https流量有问题。在chrome和firefox上获得相同的消息
的哦。
出问题了
由于某些原因,Firefox无法加载此页面。
package com.quadanalytix.selenium;
import org.browsermob.proxy.ProxyServer;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Test2 {
public static void main(String[] args) throws Exception {
ProxyServer server = new ProxyServer(4446);
server.start();
// get the Selenium proxy object
Proxy proxy = new Proxy();
proxy.setSslProxy("localhost:4446");
proxy.setHttpProxy("localhost:4446");
//captures the moouse movements and navigations
server.setCaptureHeaders(true);
server.setCaptureContent(true);
// configure it as a desired capability
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.PROXY, proxy);
System.setProperty("webdriver.chrome.driver", "/Users/tarunaggarwal/Desktop/Selenium/ChromeDriver");
// start the browser up
WebDriver driver = new ChromeDriver(capabilities);
server.newHar("gmail");
driver.get("https://www.gmail.com/");
server.stop();
driver.quit();
}
}
为什么要创建一个新的Java代理对象而不是下面的?
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.PROXY, server.seleniumProxy());
你可以在chrome浏览器上尝试以下操作吗:
ChromeOptions options = new ChromeOptions()
options.addArguments("--proxy-server=localhost:4446")
driver = new ChromeDriver(options)