how to get the full contents of a node using xpath & lxml?

后端 未结 2 2012
借酒劲吻你
借酒劲吻你 2021-01-13 01:46

I am using lxml\'s xpath function to retrieve parts of a webpage. I am trying to get contents of a tag, which includes html tags of its own. If I u

2条回答
  •  再見小時候
    2021-01-13 02:32

    I'm not sure I understand -- is this close to what you are looking for?

    import lxml.etree as le
    import cStringIO
    content='''\
    inside something
    '''
    doc=le.parse(cStringIO.StringIO(content))
    
    xpath='//font[@face="verdana" and @color="#ffffff" and @size="2"]/child::*'
    x=doc.xpath(xpath)
    print(map(le.tostring,x))
    # ['inside something']
    

提交回复
热议问题