views:

34

answers:

2

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" class="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.

A: 
//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.

Sjoerd
Thanks for the reply, but when I do "//table[@border='0' and @cellspacing='0' and @cellpadding='0']/tr[td = '1']/td[2]/a" my query returns nothing I suspect this is because the 1 we used lacked a period so when i tried "//table[@border='0' and @cellspacing='0' and @cellpadding='0']/tr[td = '1.']/td[2]/a" my program crashed out(like it usually does when I input invalid xpath commands).
http://stackoverflow.com/questions/247135/using-xpath-to-search-text-containing-
Sjoerd
A: 

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.

Dimitre Novatchev
Worked perfectly