我是phyton的初学者,我一直用它来代替我的反算计算爱好。
tghw完成了这段代码(https://github.com/tghw/macproxy),它可以过滤除链接之外的所有内容,以便可以在Macintosh classic中打开它。 我想将它改编为Windows 3.1,如何添加一个不会过滤图像的漂亮的汤标签?
提前谢谢
from bs4 import BeautifulSoup
def macify(html):
soup = BeautifulSoup(html)
for tag in soup(['script', 'link', 'style', 'noscript']):
tag.extract()
for tag in soup(['div', 'span']):
tag.replaceWithChildren()
for tag in soup():
for attr in ['style', 'onclick',]:
del tag[attr]
return str(soup)
if __name__ == '__main__':
import requests
html = requests.get('http://stackoverflow.com/questions/5598524/can-i-remove-script-tags-with-beautifulsoup').content
html = macify(html)
with open('macified.html', 'w') as fd:
fd.write(html)