【问题标题】:convert python lxml node to string without tostring将python lxml节点转换为没有tostring的字符串
【发布时间】:2015-09-15 23:14:14
【问题描述】:

是否可以在没有"tostring" 函数的情况下将 lxml xpath'ed 节点转换为字符串?

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

【问题讨论】:

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

标签: python lxml


【解决方案1】:

是的,这是可能的,即使不是非常容易。

这与之前收到的an awesome answer 问题类似。您应该能够使用类似的实现,根据您的需求量身定制。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-29
    • 1970-01-01
    • 1970-01-01
    • 2011-08-28
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    相关资源
    最近更新 更多