我有这个html
<td width="70%">REGEN REAL ESTATE, Dubai – U.A.E
RERA ID: 12087
Specialist Licensed Property Brokers & Consultants
Residential / Commercial – Buying, Selling, R <a href="http://www.justproperty.com/company_view/index/3963">...Read more...</a></td>
我想得到td
中的所有文本
但我只有最后一行。在
我该怎么做才能得到所有的台词?在
您可以使用
u"".join(selector.xpath('.//td//text()').extract())
或u"".join(selector.css('td ::text').extract())
我几乎忘记了最简单的方法,如果您想要特定节点的每个文本内容,可以直接在其上使用
normalize-space()
:请记住,
normalize-space()
将只考虑作为参数的节点集中的第一个节点,因此,如果您确定参数将匹配您想要的一个节点,那么它通常会执行您想要的操作。在normalize-space(//td/text())
适合我。在演示(使用xmlint):
其中
input.xml
包含您提供的xml。在相关问题 更多 >
编程相关推荐