python模块
一 python文章索引
To tal number is :102 python基础: python类库: python实例: python技巧: python其他:
二 python31代码用来自动生成本索引 (需要保存为utf-8格式)
1 #-*- coding: utf-8 -*- 2 3 import urllib.request 4 import re 5 6 pythontagurl = "http://www.cnblogs.com/itech/category/170012.html" 7 pythonarticleurlregrex = "(([Pp]ython.*?))" 8 9 # get the page content string which contains all python article links10 pythontagpage = urllib.request.urlopen(pythontagurl)11 pythontagstr = ""12 for line in pythontagpage.readlines():13 try:14 newline = line.decode('utf-8', 'strict')15 #print(newline)16 except:17 continue18 pythontagstr += newline19 pythontagpage.close()20 21 # get all link and sort 22 pythonlinkandtiles = re.findall(pythonarticleurlregrex, pythontagstr)23 d = dict()24 for link, title in pythonlinkandtiles:25 d[title] = link26 pythontitles = list(d.keys())27 bstr1 = "python基础"28 bstr2 = "python语法"29 estr = "python实例"30 lstr = "python类库"31 tstr = "python技巧"32 ostr = "python其他"33 basic = []34 examples = []35 libs = []36 tips = []37 others = []38 for k in pythontitles:39 if k.startswith(bstr1) or k.startswith(bstr2):40 basic.append(k)41 elif k.startswith(estr) :42 examples.append(k)43 elif k.startswith(lstr) :44 libs.append(k)45 elif k.startswith(tstr):46 tips.append(k)47 else:48 others.append(k)49 basic.sort()50 libs.sort()51 examples.sort()52 tips.sort()53 others.sort()54 55 pythonarticles = []56 fonts = " "57 fonte = ":"58 pythonarticles.append( fonts + bstr1 + fonte )59 for py in basic: pythonarticles.append(d[py]) 60 pythonarticles.append(fonts + lstr + fonte )61 for py in libs: pythonarticles.append(d[py])62 pythonarticles.append(fonts + estr + fonte ) 63 for py in examples: pythonarticles.append(d[py]) 64 pythonarticles.append(fonts + tstr + fonte )65 for py in tips: pythonarticles.append(d[py])66 pythonarticles.append(fonts + ostr + fonte )67 for py in others: pythonarticles.append(d[py]) 68 69 # generate pythonindex.html70 pythonindex = open("pythonindex.html", "w",encoding='utf-8')71 pythonindex.write("")72 pythonindex.write("")73 pythonindex.write(" ")74 pythonindex.write(" Python - iTech's Blog ")75 pythonindex.write("")76 pythonindex.write("")77 pythonindex.write("Total number is :" + str(len(pythonarticles)) + " ")78 for pa in pythonarticles:79 pythonindex.write(pa)80 pythonindex.write(" ")81 pythonindex.write("")82 pythonindex.write("")83 pythonindex.close()
作者:
出处: