zoukankan      html  css  js  c++  java
  • python学习笔记(21)--新建html乱码(给每本漫画生成一个html)

    说明:

    1. open("index.html","w",encoding="utf-8"),open的第三个参数可以设置编码格式。

    2. 代码作用是给每个文件夹新建一个index.html文件,显示文件夹里的所有图片。

     1 #!/usr/bin/python  
     2 # -*- coding: utf-8 -*-
     3 import os
     4 
     5 pathMain = r"E:manhuamh"
     6 # print(path)
     7 for paths, folders, filenames in os.walk(pathMain):
     8     # print(folders)
     9     for folder in folders:
    10         root = os.path.join(paths,folder)
    11         page = len(os.listdir(root))
    12         # print(page)
    13         os.chdir(root)
    14         html = open("index.html","w",encoding="utf-8")
    15         text = '''
    16             <!DOCTYPE html>
    17             <html lang="en">
    18             <head>
    19                 <meta charset="UTF-8">
    20                 <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes" />
    21                 <title>'''+folder+'''</title>
    22                 <style type="text/css">
    23                     body{
    24                         text-align: center;
    25                     }
    26                 </style>
    27             </head>
    28             <body>
    29                 <h1>'''+folder+'''</h1>
    30                 <div id="div">
    31                 </div>
    32             </body>
    33             <script type="text/javascript">
    34                 var page = '''+str(page)+''';
    35                 var text = "";
    36                 for (var i = 0; i < page; i++) {
    37                     text += '<img src="'+i+'.jpg" alt="">';
    38                 }
    39                 var div = document.getElementById("div");
    40                 div.innerHTML = text;
    41             </script>
    42             </html>
    43         '''
    44         html.write(text)
    45         html.close()
  • 相关阅读:
    Android MVP架构分析
    JavaEE基本了解
    学习面试题Day09
    使用反射来实现简单工厂模式
    Android Material Design简单使用
    c语言 找最小值
    c++ 计算指定半径圆的面积
    c++ 字符串拷贝以及合并
    python yaml文件读写
    python 列表元素替换以及删除
  • 原文地址:https://www.cnblogs.com/Jacklovely/p/6546079.html
Copyright © 2011-2022 走看看