代码:
workbook = open("C:\\Users\\rabdel.WINCMPT\\Documents\\Retail Footwear.twb")
soup = BeautifulSoup(workbook)
for dashboard in soup.findAll("dashboard"):
print dashboard["name"]
if dashboard["name"] == "S1":
dashboard.extract()
for window in soup.findAll("window"):
print "class:",window["class"]
if "name" in [x[0] for x in window.attrs]:
print "name:",window["name"]
if window["name"] == "S1":
window.extract()
答案 0 :(得分:13)
最简单的方法,将输出作为字符串并写入文件:
f = open(workbook.name, "w")
f.write(soup.prettify())
f.close()
答案 1 :(得分:0)