Python HTML 编码

2024-06-11 08:21:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经和这件事斗争了一段时间。我试图将字符串写入HTML,但在清理完之后,格式有问题。下面是一个例子:

paragraphs = ['Grocery giant and household name Woolworths is battered and bruised. ', 
'But behind the problems are still the makings of a formidable company']

x = str(" ")
for item in paragraphs:
    x = x + str(item)
x

输出:

"Grocery giant and household name\xc2\xa0Woolworths is battered and\xc2\xa0bruised. 
But behind the problems are still the makings of a formidable\xc2\xa0company"

期望输出:

"Grocery giant and household name Woolworths is battered and bruised. 
But behind the problems are still the makings of a formidable company"

我希望你能解释为什么会发生这种事,以及我如何解决。提前谢谢!


Tags: andofthenameisarebutproblems