"网页消耗带宽?"

2024-04-20 13:52:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用selenium webdriver打开一个网页

vdisplay = Xvfb()
vdisplay.start()
fox = webdriver.Firefox()
fox.get(url)

有没有办法知道下载时网页消耗了多少带宽(mb)?你知道吗


Tags: url网页getseleniummbfirefoxstartwebdriver
1条回答
网友
1楼 · 发布于 2024-04-20 13:52:36

使用BrowserMob代理API获取打开的页面下载大小和带宽。 对于python,使用http://browsermob-proxy-py.readthedocs.org/en/latest/

使用它很简单 例如google页面

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.com")
proxy.har # returns a HAR JSON blob

server.stop()
driver.quit()

最后把数据从代理.har像http://www.softwareishard.com/har/viewer/这样的观众

相关问题 更多 >