将 python lxml 节点转换为不带 tostring 的字符串
convert python lxml node to string without tostring
是否可以在没有 "tostring"
函数的情况下将 lxml xpath 节点转换为字符串?
from lxml import etree
tree = etree.HTML(content)
head = tree.xpath('//head')[0]
head = etree.tostring(head)
是的,这是可能的,即使不是很容易。
这与之前收到 an awesome answer 的问题类似。您应该能够使用类似的实现,根据您的需要量身定制。
是否可以在没有 "tostring"
函数的情况下将 lxml xpath 节点转换为字符串?
from lxml import etree
tree = etree.HTML(content)
head = tree.xpath('//head')[0]
head = etree.tostring(head)
是的,这是可能的,即使不是很容易。
这与之前收到 an awesome answer 的问题类似。您应该能够使用类似的实现,根据您的需要量身定制。