问题描述
我有这个 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), ' ', '')
说明:
normalize-space()
从其参数生成一个新字符串,其中任何前导或尾随空格(空格、制表符、NL 或 CR 字符)都被删除,任何中间空格都被替换为单个空格字符.
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, ' 	 
', '')
这篇关于删除空格的 xpath 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!