python怎么解码_Python如何解码编码html中的&quot等字符

如图出现html转义编码的字符,比如引号变为&quot。

解决方法:

使用自带html库中的unescape

import html

html_str = "{\"mentioned\":1,\"replied\":2,\"quoted\":3,\"edited\":4,\"liked\":5,\"private_message\":6,\"invited_to_private_message\":7,\"invitee_accepted\":8,\"posted\":9,\"moved_post\":10,\"linked\":11,\"granted_badge\":12,\"invited_to_topic\":13,\"custom\":14,\"group_mentioned\":15,\"group_message_summary\":16,\"watching_first_post\":17,\"topic_reminder\":18,\"liked_consolidated\":19,\"post_approved\":20,\"code_review_commit_approved\":21,\"membership_request_accepted\":22,\"membership_request_consolidated\":23,\"bookmark_reminder\":24,\"reaction\":25,\"votes_released\":26,\"event_reminder\":27,\"event_invitation\":28}"

text = html.unescape(html_str)

str = text.replace('\\', '')

print(str)

结果

{"mentioned":1,"replied":2,"quoted":3,"edited":4,"liked":5,"private_message":6,"invited_to_private_message":7,"invitee_accepted":8,"posted":9,"moved_post":10,"linked":11,"granted_badge":12,"invited_to_topic":13,"custom":14,"group_mentioned":15,"group_message_summary":16,"watching_first_post":17,"topic_reminder":18,"liked_consolidated":19,"post_approved":20,"code_review_commit_approved":21,"membership_request_accepted":22,"membership_request_consolidated":23,"bookmark_reminder":24,"reaction":25,"votes_released":26,"event_reminder":27,"event_invitation":28}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值