lxml.etree,element.text不会从元素返回整个文本 [英] lxml.etree, element.text doesn't return the entire text from an element

查看:499
本文介绍了lxml.etree,element.text不会从元素返回整个文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过xpath删除了一些html,然后将其转换为etree.与此类似:

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

<td> text1 <a> link </a> text2 </td>

但是当我调用element.text时,我只会得到text1(必须在那儿,当我在FireBug中检查查询时,该元素的文本会突出显示,嵌入的锚点元素之前和之后的文本...

but when I call element.text, I only get text1 (It must be there, when I check my query in FireBug, the text of the elements is highlighted, both the text before and after the embedded anchor elements...

推荐答案

使用element.xpath("string()")lxml.etree.tostring(element, method="text")-请参见文档.

这篇关于lxml.etree,element.text不会从元素返回整个文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆