Mryqu's Notes


  • 首页

  • 搜索
close

用Python清理XMind生成的html文件

时间: 2014-07-20   |   分类: Python     |   阅读: 31 字 ~1分钟

XMind思维导图可以导出成html文件,但是每个Topic都被a标签包着,然后外面再被h1、h2…h5标题标签包着,看着就难受。此外h1、h2…h5和p标签都加了class属性,没什么用。 写一段小程序,将XMind生成的html文件进行格式清理。

from bs4 import BeautifulSoup as BeautifulSoup
soup = BeautifulSoup(open("c:/qutemp/123.html"))
for a in soup('a'):
    a.parent.string = a.string
    a.clear()
for tag in ['h1','h2','h3','h4','h5','p']:
    for tag in soup(tag):
        del tag['class']
print soup

标题:用Python清理XMind生成的html文件
作者:mryqu
声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 CN 许可协议。转载请注明出处!

#python# #beautifulsoup# #xmind# #html# #清理#
磁盘分区管理工具
MySQL Workbench的安全更新模式
  • 文章目录
  • 站点概览

Programmer & Architect

662 日志
27 分类
1472 标签
GitHub Twitter FB Page
© 2009 - 2023 Mryqu's Notes
Powered by - Hugo v0.120.4
Theme by - NexT
0%