Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中使用urllib下载网页(mhtml格式)_Python_Python 2.7_Python 3.x_Selenium_Urllib - Fatal编程技术网

如何在python中使用urllib下载网页(mhtml格式)

如何在python中使用urllib下载网页(mhtml格式),python,python-2.7,python-3.x,selenium,urllib,Python,Python 2.7,Python 3.x,Selenium,Urllib,如何使用python语言中的urllib保存包含内容的网页,使其可以脱机查看?目前我正在使用以下代码: import urllib.request driver.webdriver.Chrome() driver.get("http://www.yahoo.com") urllib.request.urlretrieve("http://www.yahoo.com", C:\\Users\\karanjuneja\\Downloads\\kj\\yahoo.mhtml") 这可以工作并在文

如何使用python语言中的urllib保存包含内容的网页,使其可以脱机查看?目前我正在使用以下代码:

import urllib.request 

driver.webdriver.Chrome()
driver.get("http://www.yahoo.com")
urllib.request.urlretrieve("http://www.yahoo.com", C:\\Users\\karanjuneja\\Downloads\\kj\\yahoo.mhtml")
这可以工作并在文件夹中扫描网页的mhtml版本,但当您打开文件时,您将只看到编写的代码,而不会看到网页在线显示的方式。我们需要修改代码吗? 另外,是否有其他方法可以将网页保存为MHTML格式,并将其显示在网上的所有内容,而不仅仅是来源。有什么建议吗?
谢谢Karan我想这个网站可能会对你有所帮助~

您必须告诉操作系统,扩展名为
.mhtml
的文件实际上是HTML文件。(
.mhtml
是HTML文件的一个不寻常的扩展名。)或者,最好使用标准扩展名,如
.htm
.HTML
。非常感谢,它确实帮助了我,让事情变得简单