Selenium get HTTP response headers or access browser download history

I am using python 2.7 and the selenium driver downloaded from

pip install selenium

How can I get http headers from a web request.

In particular, I press the button / link, and the server responds with a response containing the csv file.

It would be great if I could get the file name from the http headers.

Another option: e to access the browser boot history.

Any ideas on how to achieve the above?

+4
source share
1 answer

Selenium cannot do this (network traffic capture). I would suggest using a third-party tool like Browser Mob

, ... . , os.path.getmtime

import os

from selenium import webdriver

fp = webdriver.FirefoxProfile()

fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir", "/tmp/empty-dir")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream")

browser = webdriver.Firefox(firefox_profile=fp)
browser.get("http://pypi.python.org/pypi/selenium")
browser.find_element_by_partial_link_text("selenium-2").click()

os.listdir("/tmp/empty-dir")
['selenium-2.44.0.tar.gz']
+4

All Articles