Selenium get http response headers or access the browsers's download history
Question: I use python 2.7 and the selenium driver as downloaded from

    
    
    pip install selenium
    

How can I get the http headers from a web request.

In particular I click a button/link and the server replies with a response
containing a csv file.

It would be awesome if I could get the filename from the http headers.

Another option would e to access the browser's download history.

Any ideas how the above can be achieved?


Answer: Selenium can't actually do this (capture network traffic). I would suggest
using a third party tool like [Browser
Mob](https://github.com/lightbody/browsermob-proxy)

I don't know if you can get your browser's download history... but as a
workaround you can just [download files](http://selenium-
python.readthedocs.org/faq.html) to an empty directory, and just call that
your download history. You could also rank files by time downloaded using
`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']
    

