给出以下HTML代码:
<tr>
<th scope="row" class="navbox-group">Family</th>
<td class="navbox-list navbox-even hlist" style="text-align:left;border-left-width:2px;border-left-style:solid;width:100%;padding:0px">
<div style="padding:0em 0.25em">
<ul>
<li><a href="/wiki/Andrew_Parker_Bowles" title="Andrew Parker Bowles">Andrew Parker Bowles</a> <small>(first husband)</small></li>
<li><a href="/wiki/Tom_Parker_Bowles" title="Tom Parker Bowles">Tom Parker Bowles</a> <small>(son)</small></li>
<li><a href="/wiki/Laura_Lopes" title="Laura Lopes">Laura Lopes</a> <small>(daughter)</small></li>
<li><a href="/wiki/Charles,_Prince_of_Wales" title="Charles, Prince of Wales">Charles, Prince of Wales</a> <small>(second husband)</small></li>
<li><a href="/wiki/Bruce_Shand" title="Bruce Shand">Bruce Shand</a> <small>(father)</small></li>
<li><a href="/wiki/Rosalind_Shand" title="Rosalind Shand">Rosalind Shand</a> <small>(mother)</small></li>
<li><a href="/wiki/Annabel_Elliot" title="Annabel Elliot">Annabel Elliot</a> <small>(sister)</small></li>
<li><a href="/wiki/Mark_Shand" title="Mark Shand">Mark Shand</a> <small>(brother)</small></li>
</ul>
</div>
</td>
</tr>
我想获取tr元素中的所有href,但只能从包含以下内容的tr元素中获取:
<th scope="row" class="navbox-group">Family</th>
(其中th ='家庭')
我尝试编写以下XPath:
“// TR [@ TH = '家庭'] // A / @ HREF”
但我没有得到任何href。
非常感谢。
禾企
答案 0 :(得分:1)
请尝试以下XPath
:
//tr[th="Family"]//@href
它应该允许您从tr
获取包含th
文字"Family"