Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.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节点转换为不带tostring的字符串_Python_Lxml - Fatal编程技术网

将python lxml节点转换为不带tostring的字符串

将python lxml节点转换为不带tostring的字符串,python,lxml,Python,Lxml,是否可以在不使用“tostring”函数的情况下将lxml xpath节点转换为字符串 from lxml import etree tree = etree.HTML(content) head = tree.xpath('//head')[0] head = etree.tostring(head) 是的,这是可能的,如果不是非常容易的话 这与之前收到的一个问题类似。您应该能够使用类似的实现,根据您的需要进行定制。您到底为什么不想使用提供的tostring()函数?如果您需要一个稍微不同的

是否可以在不使用
“tostring”
函数的情况下将lxml xpath节点转换为字符串

from lxml import etree
tree = etree.HTML(content)
head = tree.xpath('//head')[0]
head = etree.tostring(head)

是的,这是可能的,如果不是非常容易的话


这与之前收到的一个问题类似。您应该能够使用类似的实现,根据您的需要进行定制。

您到底为什么不想使用提供的
tostring()
函数?如果您需要一个稍微不同的输出,并且它不是标准的输出格式,那么您很可能需要编写自己的函数…可能是