小编mic*_*lle的帖子

使用BeautifulSoup修改HTML

我想使用Beautifulsoup修改整个divHTML。我试图修改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,'##')
Run Code Online (Sandbox Code Playgroud)

html python beautifulsoup

1
推荐指数
1
解决办法
2910
查看次数

标签 统计

beautifulsoup ×1

html ×1

python ×1