python - 从 Python 中的字符串中删除“”的正则表达式

标签 python regex string substring

我正在使用以下代码从 RSS 提要中获取结果:

try:  
desc = item.xpath('description')[0].text
if date is not None:
    desc =date +"\n"+"\n"+desc
except:
    desc = None

但有时描述中包含少量 unicode html 字符,如下所示:

The text from XML looks like " and with ' and other &...; stuff

在显示内容时我不想显示它们。是否有任何正则表达式来删除 HTML 标记。

最佳答案

我用了一个叫“Unescaping XML”的东西,不知道对你有没有帮助。

参见:http://wiki.python.org/moin/EscapingXml

from xml.sax.saxutils import unescape

unescape("< & >")

'< & >'




unescape("&apos; &quot;", {"&apos;": "'", "&quot;": '"'})

'\' "'

编辑

刚刚看到这个,可能很有趣。 (未测试):unescape with urllib

关于python - 从 Python 中的字符串中删除“”的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7332502/

相关文章:

c# - 正则表达式 : .net 与 javascript 中特殊字符的差异

php - 如何从欧元 (€) 表达式中删除特定的前导和尾随字符?

c++ - 使用strcpy_s将字符串复制到char *

python - 属性错误: 'Rules' object has no attribute '_Rules__temperature'

python - 如何在 django 中显示查询集中的表名称

python - 是否有一个工具可以在没有实际移动应用程序的情况下测试移动推送通知?

php - 在 PHP5 中用多个/不同的值搜索和替换多个值?

python - Raspberry Pi 在 python 与 raspistill 中捕获的图像质量

mysql - 查找包含精确字符串的 MySQL 记录

c - 将数组打印为字符串在末尾返回奇怪的字符