qua*_*ity 3 html javascript python
我想从HTML文档中删除所有javascript代码,并保留实际文本。是否有任何正则表达式或python脚本可以做到这一点?谢谢。
#!/usr/bin/env python
from BeautifulSoup import BeautifulSoup
with open("with-scripts.html", "r") as f:
soup = BeautifulSoup(f.read())
for script in soup("script"):
script.extract()
with open("without-scripts.html", "w") as f:
f.write(soup.prettify())
Run Code Online (Sandbox Code Playgroud)