美文网首页
Python如何解码编码html中的"等字符

Python如何解码编码html中的"等字符

作者: 是东东 | 来源:发表于2020-12-21 17:07 被阅读0次

如图出现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}

相关文章

网友评论

      本文标题:Python如何解码编码html中的"等字符

      本文链接:https://www.haomeiwen.com/subject/mnzrnktx.html