美文网首页
xpath取出div里面的html内容,非元素,纯html字符串

xpath取出div里面的html内容,非元素,纯html字符串

作者: 阿敏其人 | 来源:发表于2018-11-24 14:13 被阅读14次
    from lxml import etree
    
    tree = etree.fromstring('<html><head><title>foo</title></head><body><div class="name"><p>foo</p></div><div class="name"><ul><li>bar</li></ul></div></body></html>')
    for elem in tree.xpath("//div[@class='name']"):
         # pretty_print ensures that it is nicely formatted.
         print etree.tostring(elem, pretty_print=True)
    

    ref:https://stackoverflow.com/questions/14896302/get-the-inner-html-of-a-element-in-lxml

    相关文章

      网友评论

          本文标题:xpath取出div里面的html内容,非元素,纯html字符串

          本文链接:https://www.haomeiwen.com/subject/rtxyqqtx.html