有两种方法可以为您提供有意义的数据。
- 将Browsermob代理与Selenium一起使用。这是python中的示例,但在Java中几乎相同
from browsermobproxy import Server server = Server("path/to/browsermob-proxy") server.start() proxy = server.create_proxy() from selenium import webdriver profile = webdriver.FirefoxProfile() profile.set_proxy(proxy.selenium_proxy()) driver = webdriver.Firefox(firefox_profile=profile) proxy.new_har("google") driver.get("http://www.google.co.uk") proxy.har # returns a HAR JSON blob proxy.stop() driver.quit()从中返回的HAR文件
proxy.har,它只是一个JSON
blob,将为您提供所需的信息。我今年早些时候在博客上写过
- 另一种方法是使用现代浏览器中可用的导航时序规范。您所需要做的就是执行一些javascript,您将获得页面加载等详细信息。
((JavascriptExecutor)driver).executescript("var performance = window.performance || {};" + "var timings = performance.timing || {};"+ "return timings;"); 


