开发者

XPath Text Search/Sibling Selection

This question might be a little specific but the test program im writing uses XPath to find the data i need in HTML. This piece of HTML(found here) is what im trying to parse.

<table border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td class="textSm" align="right">1.&nbsp;</td> <!-- Location of the number is here -->
        <td align="left" nowrap>
            <a href="/stats/individual_stats_player.jsp?c_id=sf&playerID=467055" class="textSm">P Sandoval</a> <!-- Player location is here of the number is here -->
        </td>
    </tr>
</table>

My goal is to find the name of the person by using the number that corresponds to him to find him. This requires me to find a node by the specific text contained in "td class="textSm" align="right">1. </td>" and then find the sibling of that node "<td align="left" nowrap>" then find the child of that sibling "<a href="/stats/individual_stats_player.jsp?c_id=sf&playerID=467055" clas开发者_Go百科s="textSm">P Sandoval</a>" to get the desired result. I was wondering what kind of query I could use to find this. Any help is very much appreciated.


Use:

table/tr/td[starts-with(., '1.')]/following-sibling::td/a

This assumes that the context (current node) against which the XPath expression above is evaluated, is the parent of table.


//tr[td = "1"]/td[2]/a

For all TRs which have a TD equal to '1', give from the second child TD the A element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜