如何在Python中解开撇号等? [英] How to unescape apostrophes and such in Python?

查看:238
本文介绍了如何在Python中解开撇号等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有如下符号的字符串:

I have a string with symbols like this:

'

显然这是一个撇号。

我尝试saxutils.unescape()没有任何运气和尝试urllib.unquote()

I tried saxutils.unescape() without any luck and tried urllib.unquote()

我该如何解码?谢谢!

推荐答案

查看此问题。你要找的是html实体解码。通常情况下,您会发现一个名为htmldecode的函数将会执行所需的操作。 Django和Cheetah都提供了BeautifulSoup的功能。

Check out this question. What you're looking for is "html entity decoding". Typically, you'll find a function named something like "htmldecode" that will do what you want. Both Django and Cheetah provide such functions as does BeautifulSoup.

如果您不想使用库并且所有实体都是数字的,其他答案将会很好。

The other answer will work just great if you don't want to use a library and all the entities are numeric.

这篇关于如何在Python中解开撇号等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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