通过Python转义HTML中的单引号?

我试图通过webrowser打开一个html页面, 但是我似乎无法转义单引号来进行正确的html解析。

我正在尝试cgi和html转义, 但都产生原始字符串。

text = ' Elon Musk: ‘Give People Back Their Goddamn Freedom’'




cgi.escape(text)
 >>> ' Elon Musk: ‘Give People Back Their Goddamn Freedom’'

html.escape也会产生没有转义的原始字符串

谢谢。

更新:

转义转换可以使用html.escape或cgi, https://www.freeformatter.com/html-escape.html正常运行, 但不能引用围绕Elon Musk的报价。因此无法使用Webrowser正确读取html


#1


只需将他的角色放在你需要转义的每个引号前面:

text = ' Elon Musk: \‘Give People Back Their Goddamn Freedom\’'

来源:

https://www.srcmini02.com/57960.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_35256.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?