from html import unescape
html_content = unescape(str(pq_html))
测试文本:
<div onclick="tzbszn();" style="cursor:pointer;"><img src="/images/detailbszn.png" style="width:88px;height:88px;position:absolute;top:150px;right:35px;"/></div>
<div onclick="tzwytb();" style="cursor:pointer;"><img src="/images/detailwytb.png" style="width:88px;height:88px;position:absolute;top:250px;right:35px;"/></div>
<!-- foot begin -->
<div id="foot"/>
<!-- foot finish -->
输出:
<div onclick="tzbszn();" style="cursor:pointer;"><img src="/images/detailbszn.png" style="width:88px;height:88px;position:absolute;top:150px;right:35px;"/></div>
<div onclick="tzwytb();" style="cursor:pointer;"><img src="/images/detailwytb.png" style="width:88px;height:88px;position:absolute;top:250px;right:35px;"/></div>
<!-- foot begin -->
<div id="foot"/>
<!-- foot finish -->
如果需要转义回去,可以使用
from html import escape
参考资料:
python中HTML文档转义与反转义方法介绍
https://www.csdn.net/gather_28/MtTaIg0sNDYyODktYmxvZwO0O0OO0O0O.html