删除空格的 xpath 表达式 [英] xpath expression to remove whitespace

查看:41
本文介绍了删除空格的 xpath 表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 HTML:

 <tr class="even  expanded first>
   <td class="score-time status">
     <a href="/matches/2012/08/02/europe/uefa-cup/">

            16 : 00

     </a>
    </td>        
  </tr>

我想提取没有多余空格的 (16 : 00) 字符串.这可能吗?

I want to extract the (16 : 00) string without the extra whitespace. Is this possible?

推荐答案

I.使用这个单一的 XPath 表达式:

translate(normalize-space(/tr/td/a), ' ', '')

说明:

  1. normalize-space() 从其参数生成一个新字符串,其中任何前导或尾随空格(空格、制表符、NL 或 CR 字符)都被删除,任何中间空格都被替换为单个空格字符.

  1. normalize-space() produces a new string from its argument, in which any leading or trailing white-space (space, tab, NL or CR characters) is deleted and any intermediary white-space is replaced by a single space character.

translate() 使用 normalize-space() 产生的结果并产生一个新字符串,其中每个剩余的中间空格都被空字符串替换.

translate() takes the result produced by normalize-space() and produces a new string in which each of the remaining intermediary spaces is replaced by the empty string.

<小时>

二.或者:

translate(/tr/td/a, ' &#9;&#10;&#13', '')

这篇关于删除空格的 xpath 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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