我想用selenium和python下载一个.mhtml格式的网页。我使用以下代码:
driver = webdriver.Chrome()
driver.get("http://www.yahoo.com")
with open("/path/to/page_source.mhtml", "w", encoding="utf-8") as f:
f.write(driver.page_source)它保存了页面,但是页面上只有源代码。无法查看页面上的原始内容。有什么建议吗?
谢谢卡兰
发布于 2022-08-02 09:02:58
你可以试试这个:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
options.add_argument('--save-page-as-mhtml')
driver = webdriver.Chrome(options = options, service=ChromeService(ChromeDriverManager().install()))
driver.get("http://www.yahoo.com")
with open("page_source.mhtml", "w", encoding="utf-8") as f:
f.write(driver.page_source)https://stackoverflow.com/questions/42911209
复制相似问题