【问题标题】:python xpath remove unicode charspython xpath删除unicode字符
【发布时间】:2014-02-22 21:48:58
【问题描述】:

我在 html 页面中有这段文字

<div class="phone-content">

                            ‪050 2836142‪

                    </div>

我是这样提取的:

我正在使用 xpath 来提取该 div 中的值。

normalize-space(.//div[@class='fieldset-content']/span[@class='listing-reply-phone']/div[@class='phone-content']/text())

我得到了这个结果:

"\u202a050 2836142\u202a"

有人知道谁告诉 python 中的 xpath 删除那个 unicode 字符吗?

【问题讨论】:

标签: python python-2.7 xpath unicode


【解决方案1】:

如果您正在寻找 XPath 解决方案:要删除给定集中的字符以外的所有字符,您可以按照以下模式使用两个嵌套的 translate(...) 调用:

translate($string, translate($string, ' 0123456789', ''), '')

这将删除所有不是空格字符或数字的字符。您必须用完整的 XPath 表达式替换两次出现的 $string 才能获取该字符串。

使用更高级的字符串操作功能在 XPath 之外应用它可能更合理。 XPath 1.0 的功能非常有限。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-23
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    • 2018-04-01
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    相关资源
    最近更新 更多