简体   繁体   中英

how to use xpath get all child node text?

<tr>
<td width="120" align="right" class="tit">Name:</td>
<td style="width:345px;word-break:break-all;">
<a style="text-decoration: underline;color: #0066ff;cursor: pointer" href="javascript:_search('pin','Jack');">Jack</a>;
<a style="text-decoration: underline;color: #0066ff;cursor: pointer" href="javascript:_search('pin','Eva');">Eva</a>;
</td>
</tr>

I want return "Jack;Eva", but I just get Jack with below code. How to get all names? There are different counts of names.

html.xpath('//td[contains(text(),"Name")]/following-sibling::td[1]/a/text()')[0]

Like this (removed [1] ), and you have to remove trailing [0] which limit your results at the first match:

//td[contains(text(),"Name")]/following-sibling::td/a/text()

Output

Jack
Eva

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM