Generate Activation Code
#!/usr/bin/env Python#encoding:utf-8#author:seanimport Stringimport random# The characters and numbers in the Activation Code field = String.letters + string.digits# get four letters and numbers in a random combination def getrandom (): Return '. Join (Random.sample (field,4)) #生成的每个激活码中有几组def concatenate (gr OUP): Return '-'. Join ([Getrandom () for I in Range (group)]) #生成n组激活码def Generate (N): Return [CONCATENATE (4) for I In range (n)] if __name__ = = ' __main__ ': print Generate (10)
Statistical words
#!/usr/bin/env Python#encoding:utf-8import refrom Collections Import Counterfilesource = './media/abc.txt ' Def Getmostcommonword (Articlefilesource): "Enter an English plain text file that counts the number of occurrences of the word ' pattern = R ' [a-za-z]+|\$?\d+%?$ ' with open ( Articlefilesource) as F:r = Re.findall (Pattern,f.read ()) return Counter (R). Most_common () if __name__ = = ' __main__ ': Print Getmostcommonword (Filesource)
Extract page body
#!/usr/bin/env python#encoding:utf-8from Goose Import goosefrom goose.text import Stopwordschineseimport sys# To parse the page Urlurl = ' def extract (URL): ' Extract the page body ' ' G = Goose ({' Stopwords_class ': Stopwordschinese}) Artlcle = G.extract (Url=url) return artlcle.cleaned_textif __name__ = = ' __main__ ': Print extract (URL)
This article is from the "Home" blog, please make sure to keep this source http://itchentao.blog.51cto.com/5168625/1899821
Python application case