排除某些特定元素的 xpath [英] xpath that exclude some specific elements

查看:26
本文介绍了排除某些特定元素的 xpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要分析的页面 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">&nbsp;</td>
      <td class="class_4">&nbsp;</td>
      <td class="class_5">&nbsp;</td>
    </tr>
    <tr class="class_2">
      <td class="class_3">&nbsp;</td>
      <td class="class_4">&nbsp;</td>
      <td class="class_5"><span class="class_6"></span>square</td>
    </tr>
    <tr class="class_2">
      <td class="class_3">&nbsp;</td>
      <td class="class_4">&nbsp;</td>
      <td class="class_5"><span class="class_7"></span>circle</td>
    </tr>
    <tr class="class_2">
      <td class="class_3">&nbsp;</td>
      <td class="class_4">&nbsp;</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> 减去那些具有 &nbsp;.

    I need to obtain all the <td> with class="class_5" minus the ones that have &nbsp; 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 code U+00A0 that you can input from keyboard in windows using alt+0160 where numbers are to be input from numpad.

    这篇关于排除某些特定元素的 xpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆