【问题标题】:Need to capture network traffic using proxy in selenium webdriver code需要在 selenium webdriver 代码中使用代理来捕获网络流量
【发布时间】:2014-01-20 20:49:56
【问题描述】:

需要在 selenium webdriver 代码中使用代理捕获网络流量。我尝试使用以下代码,但打开浏览器后 google.com 未加载,出现错误“拒绝连接的代理服务器”

public class Test_One {

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
ProxyServer server = new ProxyServer(8090);
         server.start();
         server.setCaptureHeaders(true);

         server.setCaptureContent(true);
         server.newHar("test");
         DesiredCapabilities capabilities = new DesiredCapabilities();
         Proxy proxy = server.seleniumProxy();
         FirefoxProfile profile = new FirefoxProfile();
         profile.setAcceptUntrustedCertificates(true);
         profile.setAssumeUntrustedCertificateIssuer(true);
         profile.setPreference("network.proxy.http", "localhost");
         profile.setPreference("network.proxy.http_port", 8090);
         profile.setPreference("network.proxy.ssl", "localhost");
         profile.setPreference("network.proxy.ssl_port", 8090);
         profile.setPreference("network.proxy.type", 1);
         profile.setPreference("network.proxy.no_proxies_on", "");
         profile.setProxyPreferences(proxy);
         capabilities.setCapability(FirefoxDriver.PROFILE,profile);
         capabilities.setCapability(CapabilityType.PROXY, proxy);
         WebDriver driver = new FirefoxDriver(capabilities);
         driver.get("http://www.google.com");
         Har har1 = server.getHar();
         server.stop();
         driver.quit();
         }
}

【问题讨论】:

  • 您找到解决方案了吗?我也有类似的问题!

标签: java firefox proxy selenium-webdriver


【解决方案1】:

类似话题:https://stackoverflow.com/a/55202231/2917470

您可以尝试 moxproxy 来捕获或修改 http 流量 - github repo

例子here

【讨论】:

    【解决方案2】:

    最新版本的 Selenium Webdriver 并不真正支持流量捕获。但是,您可以使用 BrowserMob 代理来捕获流量。 https://github.com/lightbody/browsermob-proxy 。自述文件中包含有关如何使用 Selenium 执行此操作的示例。

    【讨论】:

      猜你喜欢
      • 2015-03-25
      • 2021-02-28
      • 1970-01-01
      • 1970-01-01
      • 2019-11-04
      • 1970-01-01
      • 2021-07-03
      • 2022-10-16
      • 2018-01-15
      相关资源
      最近更新 更多