pad
pad

Reputation: 2396

Getting the bandwidth consumed by a webpage?

I am using the selenium webdriver to open a webpage

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

Is there any way to know how much bandwidth (in mb) is consumed by the webpage on download?

Upvotes: 1

Views: 586

Answers (1)

Bhupesh
Bhupesh

Reputation: 231

use BrowserMob Proxy API for getting opened page download size and bandwidth. For python use http://browsermob-proxy-py.readthedocs.org/en/latest/

using it is simple enough For example for google page

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()

At last put data from proxy.har to a harviewer like http://www.softwareishard.com/har/viewer/

Upvotes: 2

Related Questions