#!/usr/bin/python # coding:utf-8 import os def iter(path): for root, dirs, files in os.walk(path): for fn in files: if fn.endswith(".html"): with open(root + '/' + fn, 'r') as f: content = f.read() content = content.replace('', '').replace('', '') insert_pos = content.find("", content.find("Generated using GitBook")) + 6 content = content[:insert_pos] + '''
  • ''' + content[insert_pos:] content.replace(r'.*?', "《The Swift Programming Language》完整中文版") with open(root + '/' + fn, 'w') as f: f.write(content) iter(os.getcwd())