要在页面加载完成之前仅获取网络日志(在页面的主要使用过程中没有ajax/async网络日志),可以获取性能日志:http://chromedriver.chromium.org/logging/performance-log
例如,要启用ChromeDriver的性能日志记录DesiredCapabilities cap = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
cap.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"), cap);
同样,重要的是要记住,这只会让网络请求直到页面加载完成。之后,驱动程序将只返回相同的性能日志,直到页面重新加载。
如果希望在整个页面使用过程中异步获取网络日志,可以使用BrowserMobProxy充当Selenium驱动程序的代理服务器并捕获所有这些网络请求。然后,您可以从BrowserMobProxy生成的HAR文件中获取捕获的请求:https://github.com/lightbody/browsermob-proxy#using-with-selenium// start the proxy
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.start(0);
// get the Sele
最后
以上就是灵巧仙人掌最近收集整理的关于python获取浏览器network_如何使用python selenium获取浏览器网络日志的全部内容,更多相关python获取浏览器network_如何使用python内容请搜索靠谱客的其他文章。
发表评论 取消回复