Save a Web Page with Python Selenium

python, selenium

Solution

Unfortunately you can't do what you would like to do with Selenium. You can use page_source to get the html but that is all that you would get.

Selenium unfortunately can't interact with the Dialog that is given to you when you do save as.

You can do the following to get the dialog up but then you will need something like AutoIT to finish it off

from selenium.webdriver.common.action_chains import ActionChains

saveas = ActionChains(driver).key_down(Keys.CONTROL)\
         .send_keys('s').key_up(Keys.CONTROL)
saveas.perform()

Problem

I am using selenium webdriver for Python 2.7: Start a browser: `browser = webdriver.Firefox()`. Go to some URL: `browser.get('http://www.google.com')`. At this point, how can I send a 'Save Page As' command to the browser? Note: It is not the web-page source that I am interested in. I would like to save the page using the actual 'Save Page As' Firefox command, which yields different results than saving the web-page source.

Original source

Related problems