【发布时间】:2016-11-23 23:39:37
【问题描述】:
我想使用 Beautifulsoup 来修改整个 HTML 的div。我试图修改 HTML,但是控制台输出有修改,但实际的 .html 文档本身没有修改。没有创建新的 HTML。
有人可以帮我吗?
from bs4 import BeautifulSoup,Tag
import re
import urllib2
import os.path
base=os.path.dirname(os.path.abspath(__file__))
html=open(os.path.join(base,'example.html'))
soup=BeautifulSoup(html,'html.parser')
for i in soup.find('div',{"id":None}).findChildren():
l=str(i);
print l
print l.replace(l,'##')
【问题讨论】:
-
您是否尝试保存文件?
from __future__ import print_function print("hi there", file=f)
标签: python html beautifulsoup