4

2 つの異なるテーブルに同じ td が 2 回あります。

これを使用して、最初の値「はい」を取得できます。

//h:td[1][*[contains(.,'Loudspeaker')]]/../h:td[last()]/text()

しかし、2 番目の値 'Voice 75dB / Noise 66dB / Ring 75dB' は得られません。私は試した:

//h:td[2][*[contains(.,'Loudspeaker')]]/../h:td[last()]/text()

私はhtmlとxpathに非常に慣れていないので、ご容赦ください。

私のhtmlの一部:

</table><table cellspacing="0">
<tr>
<th rowspan="3" scope="row">Sound</th>
<td class="ttl"><a href="glossary.php3?term=call-alerts">Alert types</a></td>
<td class="nfo">Vibration; MP3, WAV ringtones</td>
    </tr>

<tr>
<td class="ttl"><a href="glossary.php3?term=loudspeaker">Loudspeaker</a> </td>
<td class="nfo">Yes</td>
</tr>

. .

<table cellspacing="0">
<tr>
<th rowspan="5" scope="row">Tests</th>
<td class="ttl"><a href="xyz.php">Display</a></td>
<td class="nfo">
<a class="noUnd" href="http://xyz.php">Contrast ratio: Infinite (nominal) / 3.419:1     (sunlight)</a></td>
</tr><tr>

<td class="ttl"><a href="xyz.php">Loudspeaker</a></td>
<td class="nfo">
<a class="noUnd" href="http://xyz.php">Voice 75dB / Noise 66dB / Ring 75dB</a></td>
</tr><tr>

..

前もって感謝します。

4

3 に答える 3

3

これら 2 つのスニペットの唯一の違いは、2 番目のスニペットでは、テキストがa要素内にネストされていることです。だからそうでなければならない

//h:td[2][*[contains(.,'Loudspeaker')]]/../h:td[last()]/h:a/text()

h( XPathで使用するための名前空間定義があると思います。

于 2013-05-24T10:21:58.923 に答える