如何使用xpath从中提取['First one', 'Second two', 'Third']
?
s = """
<table cellpadding="0" cellspacing="0" border="0">
<tbody><tr>
<th class="searchResults" style="width:75px">First<br>one</th>
<th class="searchResults" style="width:150px">Second<br>two</th>
<th class="searchResults" style="width:95px">Third<br></th>
</tr>
</tbody></table>
"""
import lxml.html as LH
e = LH.fromstring(s)
e.xpath('/th[@class="searchResults"]/text()')
分裂<br>
也是我不想要的。我已经尝试了string()
和normalize-space()
,但无法做到这一点。
答案 0 :(得分:2)