我有一个 HTML 文件,其中包含;
<html>
<head></head>
<body><p>thanks god its Friday</p></body>
</html>a& ca-79069608498"
<div class="cont" id="aka"></div>
<footer>
<div class="tent"><div class="cont"></div>
<h2><img alt="dscdsc" height="18" src="dsc.png" srcset="" width="116"/></h2>
</div>
</footer>
ipt> (window.NORLQ=window.NORLQ||[]).push(function(){var
ns,i,p,img;ns=document.getElementsByTagName('noscript');for(i=0;i<ns.len)>-1){img=document.createEleight'));img.setAttribute('alt',p.getAttribute('data-alt'));p.parentNode.replaceChild(img,p);}}});/*]]>*/</script><script>(window.RLQ=window.RLQ||[]).push(function(
文件名是a.html
我想删除</html>
HTML 文件中的Python 2.7
所有内容,但 HTML 标签后的所有字符串都不属于标签,其中一些只是嘈杂,所以我无法使用 Beautifulsoup 来完成,我不知道使用正则表达式是否明智用于 HTML 文件。
如何在之后删除字符串</html>
并写入 HTML 文件?
使用正则表达式
import re
...
newhtml = re.sub('</html>[\s\S.]+', '</html>', oldhtml)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句