Pipo
Pipo

Reputation: 309

xpath to find value in html code

I want to use xpath to get the value "National Aeronautics and Space Administration" only from the html below

            <table style="margin: 0 5px 0 2px; font-size: 8pt;" class="joaResultsDetailsTable">

                    <tr>
                        <td><strong>Department:</strong></td>
                        <td>National Aeronautics and Space Administration</td>
                    </tr>

                    <tr>
                        <td style="width: 112px;"><strong>Agency:</strong></td>
                        <td>George C. Marshall Space Flight Center</td>
                    </tr>
                    <tr>
                        <td><strong>Open Period:</strong></td>
                        <td>9/10/2012 to 9/14/2012</td>
                    </tr>
                    <tr>
                        <td><strong>Who May Apply:</strong></td>
                        <td>
                            Current students from education institutions interested in paid opportunities wi...

                        </td>
                    </tr>
                    <tr>

                        <td style="vertical-align:top;"><strong>Location(s):</strong></td>

                            <td>Huntsville, Alabama</td>

                    </tr>
                </table>

I hope if you can help

Upvotes: 0

Views: 66

Answers (1)

C. M. Sperberg-McQueen
C. M. Sperberg-McQueen

Reputation: 25034

You don't provide much context. Any of the following XPath expressions will meet your stated requirement that the value of the expression, when evaluated against the input you show, should be the string 'National Aeronautics and Space Administration':

string(self::table/tr[td='Department:']/td[2])

string(self::table/tr[1]/td[2])

string(self::table/descendant::td[2]))

'National Aeronautics and Space Administration'

Which of these will work best for you depends on what your unstated requirements are.

Upvotes: 2

Related Questions