如何在Python中解码转义的unicode javascript代码? [英] How do I decode escaped unicode javascript code in Python?

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

问题描述

我有这样的字符串:

V posledn\u00edch m\u011bs\u00edc\u00edch se bezpe\u010dnostn\u00ed situace v Libyi zna\u010dn\u011b zhor\u0161ila, o \u010dem\u017e sv\u011bd\u010d\u00ed i ned\u00e1vn\u00e9 n\u00e1hl\u00e9 opu\u0161t\u011bn\u00ed zem\u011b nejen \u010desk\u00fdmi diplomaty. Libyi hroz\u00ed nekontrolovan\u00fd rozpad a nekone\u010d



哪些应改为Vposledních měsícíchse...
所以\ u00ed是í而\ u011b是ě。

Which should read "V posledních měsících se ..." so \u00ed is í and \u011b is ě.

任何想法如何在Python中解码?这是我在python中解析的javascript代码。我可以编写自己的临时解决方案,因为没有那么多的字符被转义(捷克语中只有12个左右的重音字符),但这看起来很难看。

Any idea how to decode this in Python? It is a javascript code I am parsing in python. I could write my own ad-hoc solution as there are not that many characters that are escaped (there are only twelve or so accented characters in Czech), but that seems ugly.

推荐答案

使用'unicode-escape'编解码器对其进行解码。如果 x 是你的字符串, x.decode('unicode-escape')。

Decode it using the 'unicode-escape' codec. If x is your string, x.decode('unicode-escape').

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

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