I'm looking for a way to save a full web page with Selenium and Python, but using a headless browser. And I want the saved page to be completely identical to how the webpage appears when we open it (just like using the "Save as..." feature in the browser.)
I tried this code snippet by Andersson (https://stackoverflow.com/a/42900364) and it works fine, but I want to use a headless browser instead. Is this possible?
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import ahk
firefox = FirefoxBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe")
from selenium import webdriver
driver = web.Firefox(firefox_binary=firefox)
driver.get("http://www.yahoo.com")
ahk.start()
ahk.ready()
ahk.execute("Send,^s")
ahk.execute("WinWaitActive, Save As,,2")
ahk.execute("WinActivate, Save As")
ahk.execute("Send, C:\\path\\to\\file.htm")
ahk.execute("Send, {Enter}")