如何使用python转换/格式化字符

问题描述 投票:0回答:1

我实际上正在尝试使用curl 检索网页的标题。 我正在使用这个代码:

curl "%URLLink%" --insecure -L > "%HTMLFile%"

但是我得到了一些未格式化的字符,它向我显示了类似这样的内容

<title> La guerre de l&#039;info : Israël / Hamas en replay - Complément d&#039;enquête </title>

而不是

<title> La guerre de l'info : Israël / Hamas en replay - Complément d'enquête </title>

我希望有一种简单的方法可以通过像这样的简单行代码来理解这一点

curl "%URLLink%" --insecure -L | python -m json.tool > "%JSONFile%"

我用它来美化 JSON 中的一些文本。

python html python-3.x python-2.7 character-encoding
1个回答
0
投票

使用 html.unescape():

import html
print(html.unescape('&pound;682m'))
© www.soinside.com 2019 - 2024. All rights reserved.