排除某些特定元素的 xpath [英] xpath that exclude some specific elements
问题描述
这是我要分析的页面 HTML 的简单版本:
This is a simple version of the HTML of the page that I want analyse:
<table class="class_1">
<tbody>
<tr class="class_2">
<td class="class_3"> </td>
<td class="class_4"> </td>
<td class="class_5"> </td>
</tr>
<tr class="class_2">
<td class="class_3"> </td>
<td class="class_4"> </td>
<td class="class_5"><span class="class_6"></span>square</td>
</tr>
<tr class="class_2">
<td class="class_3"> </td>
<td class="class_4"> </td>
<td class="class_5"><span class="class_7"></span>circle</td>
</tr>
<tr class="class_2">
<td class="class_3"> </td>
<td class="class_4"> </td>
<td class="class_5"><span class="class_6"></span>triangle</td>
</tr>
</tbody>
</table>
您可以在以下位置找到该页面https://sabbiobet.netsons.org/test.html
You can find the page at https://sabbiobet.netsons.org/test.html
如果你在谷歌表格中尝试这个功能:
If you try in a google sheets the function:
=IMPORTXML("https://sabbiobet.netsons.org/test.html";"//td[@class='class_5']")
=IMPORTXML("https://sabbiobet.netsons.org/test.html";"//td[@class='class_5']")
我会得到:
- 方形
我需要使用
class="class_5"
获得所有<td>
减去那些具有
或.
I need to obtain all the
<td>
withclass="class_5"
minus the ones that have
or<span class=class_7>
.换句话说,我只想获得这些值:
In other words I want to obtain only these values:
- 方形
- 三角形
有人可以帮我吗?
推荐答案
这应该有效:
//td[@class='class_5'][not(text()=' ')][not(./span[@class='class_7'])]
其中
[not(text()=' ')]
不是测试规则空间,而是测试具有 Unicode 代码U+00A0
的符号,您可以在 Windows 中使用alt+0160
从键盘输入,其中数字将从小键盘输入.where
[not(text()=' ')]
is not testing for a reqular space but rather for a symbol with Unicode codeU+00A0
that you can input from keyboard in windows usingalt+0160
where numbers are to be input from numpad.这篇关于排除某些特定元素的 xpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!