【发布时间】:2019-12-03 05:05:34
【问题描述】:
我正在寻找一种使用 Selenium 和 Python 保存完整网页的方法,但使用的是无头浏览器。而且我希望保存的页面与我们打开它时网页的显示方式完全相同(就像使用浏览器中的“另存为...”功能一样。)
我尝试了 Andersson (https://stackoverflow.com/a/42900364) 的这段代码 sn-p,它运行良好,但我想改用无头浏览器。这可能吗?
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}")
【问题讨论】:
标签: python selenium selenium-webdriver web-scraping headless-browser