假设以下HTML DOM:
<table id="my_id">
<tbody>
<tr>
<th>Location:</th>
<td>
1600 Parkway Ave
Los Angels
California
</td>
</tr>
</tbody>
</table>
我如何获得1600 Parkway Ave Los Angels California&#39;假设此表中有很多<tr>
?我想我需要得到包含<th>
的{{1}}的兄弟姐妹。我一直在尝试做类似的事情:
Location:
答案 0 :(得分:3)
您可以将th
谓词移至tr
...
//*[@id="my_id"]//tr[th='Location:']/td/text()
根据评论The "Location:" string actually has whitespace around it.
进行更新:
//*[@id="my_id"]//tr[normalize-space(th)='Location:']/td/text()
答案 1 :(得分:0)
简单如下:
//*[@id="my_id"]//th[text()='Location:']/../td/text()