lxml.etree, element.text doesn't return the entire text from an element

后端 未结 8 869
梦毁少年i
梦毁少年i 2021-02-07 10:39

I scrapped some html via xpath, that I then converted into an etree. Something similar to this:

 text1  link  text2 
<         


        
8条回答
  •  我寻月下人不归
    2021-02-07 10:52

    def get_text_recursive(node):
        return (node.text or '') + ''.join(map(get_text_recursive, node)) + (node.tail or '')
    

提交回复
热议问题