Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.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 lxml-另存为html文件_Python_Python 2.7_Lxml - Fatal编程技术网

Python lxml-另存为html文件

Python lxml-另存为html文件,python,python-2.7,lxml,Python,Python 2.7,Lxml,在这部法典中 import lxml.html as ht page=ht.parse("http://doc.scrapy.org/en/latest/_static/selectors-sample1.html") 我想将html页面保存为特定路径/文件夹中的html文件。如何操作?您可以使用: page.write('test.html') 这将把文件输出到您的工作目录。如果指定了适当的路径,您可以将文件输出到另一个目录。如果您只想下载并保存它,为什么需要使用lxml对其进行解析?。可

在这部法典中

import lxml.html as ht
page=ht.parse("http://doc.scrapy.org/en/latest/_static/selectors-sample1.html")
我想将html页面保存为特定路径/文件夹中的html文件。如何操作?

您可以使用:

page.write('test.html')

这将把文件输出到您的工作目录。如果指定了适当的路径,您可以将文件输出到另一个目录。

如果您只想下载并保存它,为什么需要使用
lxml
对其进行解析?。可能我想在保存之前对其进行一点处理:)指定真实html文件的方法。否则它将编写一个xml文件:
page.write('test.html,method='html')