0

我想使用 xpath 仅从下面的 html 中获取值“美国国家航空航天局”

            <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>

我希望你能帮忙

4

1 回答 1

2

您没有提供太多上下文。以下任何 XPath 表达式都将满足您声明的要求,即当针对您显示的输入进行评估时,表达式的值应该是字符串“美国国家航空航天局”:

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'

其中哪一个最适合您取决于您​​未说明的要求是什么。

于 2012-09-14T19:07:00.090 回答