如图出现html转义编码的字符,比如引号变为"。
解决方法:
- 使用自带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}
网友评论