我在 2 个不同的表中出现了 2 个相同的 td。
我可以使用这个获得第一个值"is":
//h:td[1][*[contains(.,'Loudspeaker')]]/../h:td[last()]/text()
但没有获得第二个值“语音 75dB/噪音 66dB/铃声 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>
..
提前致谢。
最佳答案
这两个片段之间的唯一区别是,在第二个片段中,您的文本嵌套在 a
元素中。所以它必须是
//h:td[2][*[contains(.,'Loudspeaker')]]/../h:td[last()]/h:a/text()
(我猜你在 XPath 中使用了 h
的命名空间定义。
关于html - 如何使用xpath在html中找到第二个td,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16732508/