我正在使用BrowserMob從Chrome瀏覽器捕獲流量。我用.bat文件下載BrowserMob應用程序。我也與Selenium Webdriver合作。我從Github將.cs文件添加到Browser項目中。我想要的是獲得網絡流量。BrowserMob無法使用Selenium Webdriver
我的代碼是:
using (IWebDriver driver = new ChromeDriver())
{
var server = new Server(@"C:\Users\Barp\Downloads\browsermob-proxy-2.1.4-bin\browsermob-proxy-2.1.4\bin\browsermob-proxy.bat");
server.Start();
Thread.Sleep(1000);
Client client = server.CreateProxy();
client.NewHar("google");
var chromeOptions = new ChromeOptions();
var seleniumProxy = new Proxy1 { HttpProxy = client.SeleniumProxy };
chromeOptions.Proxy = seleniumProxy;
Thread.Sleep(1500);
var dr = new ChromeDriver(chromeOptions);
dr.Navigate().GoToUrl("http://www.google.co.uk");
var harData = client.GetHar();
HarResult harDat = client.GetHar();
WebdriverTestGUI2.BrowserMob.Log log = harDat.Log;
WebdriverTestGUI2.BrowserMob.Entry[] entries = log.Entries;
foreach (var entry in entries)
{
WebdriverTestGUI2.BrowserMob.Request request = entry.Request;
var url = request.Url;
var time = entry.Time;
Console.WriteLine("Url: " + url + " - Time: " + time);
}
driver.Quit();
client.Close();
server.Stop()
}
}
你有什麼變化,你的.bat文件或者也許在其他BrowserMob文件?
CMD打開時,開始也工作得很好,但我有出現在cmd中的錯誤:
錯誤文件管理器(bmp.log)java.io.FileNotFound異常bmp.log(訪問被拒絕)
- 錯誤無法注入到領域的建設者類插件類型類org.apache.logging.log4j.core無法爲bmp.log
- 錯誤無法調用類類org.apache工廠方法創建經理。 logging.log4j.core.appender.FileAppender for element file java.lang.IllegalStateException:找不到工廠方法
- 文件在appenders中的錯誤NULL對象返回
-錯誤無法找到記錄器配置的appender「文件」。
好的,訪問被拒絕我已經解決了。我應該以Administrator身份運行這個BrowserMob。 – Barpe2