python生成html图_python学习笔记(22)--漫画生成html最终版

该代码实现了一个自动化过程,用于在指定目录中创建子目录的HTML索引页面和主页面。它遍历目录,为每个子目录生成一个包含目录名的`index.html`文件,并在`booklist.js`中创建一个书目列表,同时生成`main.html`作为主页面。此脚本适用于组织和浏览本地文件结构。
摘要由CSDN通过智能技术生成

1 #!/usr/bin/python

2 #-*- coding: utf-8 -*-

3 importos4

5 #pathMain = r"E:\manhua\mh"

6 pathMain =os.getcwd()7 defcreateIndex():8 for paths, folders, filenames inos.walk(pathMain):9 #print(folders)

10 for folder infolders:11 root =os.path.join(paths,folder)12 page =len(os.listdir(root))13 #print(page)

14 os.chdir(root)15 html = open("index.html","w",encoding="utf-8")16 text = '''

17 18 19

20 21 22 '''+folder+'''23 31 32 33

'''+folder+'''

34
35
36 37 46 47 '''

48 html.write(text)49 html.close()50 defcreateMain():51 filenames =os.listdir(pathMain)52 os.chdir(pathMain)53 folders =[]54 for filename infilenames:55 ifos.path.isdir(filename):56 folders.append(filename)57

58 with open("booklist.js","w",encoding="utf-8") as f1:59 txt1 = ""

60 for folder infolders:61 txt1 += "'"+folder+"'" + ","

62 booklist = '''

63 var booklist = ['''+txt1[0:-1]+'''];64 '''

65 f1.write(booklist)66 with open("main.html","w",encoding="utf-8") as f:67 txt = '''

68 69 70

71 72 73 妖气漫画74 80 81 82
83
84 85 86 95 96

97 '''

98 f.write(txt)99

100 createMain()101 createIndex()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值