1
#!/usr/bin/env python3 # -*- coding:utf-8 -*- import urllib.request import re import sys import time class UserName: def __init__(self): self.url = "http://www.wangmingdaquan.cc/" self.path = "C:\\Users\Administrator\Desktop\\username.log" #self.path = "D:\\username.log" pass def loop(self): html = self.getPage(self.url) #regex = '<a href="http://www.wangmingdaquan.cc/(.*?)/">.*?</a>' #regex = '<a href="/(.*?)/" target="_blank"></a>' regex = '<a href="http://www.wangmingdaquan.cc/(.*?)/">.*?</a>' print(html) page_list = self.comp(html, regex, 1) # return value is list typ print (page_list) sys.exit() # username searching as as belowed regex = '<p>(.*?)</p>' count = 0 for u in page_list: for n in range(60, 92): for i in range(261124, 280000): url = "www.wangmingdaquan.cc/" + u + "list_" + sti(n) +"_" + str(i) + ".html" print("now, we are scraping '"+ url + "'") html = self.getPage(url) if html == '': continue n = self.comp(html, regex) print("总数为: " + str(n)) count += n print("catch name over, total number: " + str(count)) #print("catch name over,total number: " + str(count)) def getPage(self, url): html = '' try: f = urllib.request.urlopen(url) html = f.read().decode() # bytes -> str except Exception as e: print("getPage => " + str(e)) #return return html pass def comp(self, html, regex, status=0): pattern = re.compile(regex, re.M) user_list = re.findall(pattern, html) if status: return user_list count = self.save(user_list) return count def save(self, name_list): for name in name_list: self.write_config(name) return len(name_list) def write_config(self, data): f = open(self.path, 'a') try: f.write(data.strip()+"\n") except Exception as e: print("write_config => " + str(e)) finally: f.close() return if __name__ == '__main__': user = UserName() user.loop()
#!/usr/bin/env python # -*- coding:utf-8 -*- user_info = { "zhangsan":"mima1", "lisi":"mima2", "wangwu":"mima3", } def log_auth(): user_input = raw_input() def log_auth(): user_input = raw_input("\033[32;1m请输入您的用户名:\033[0m") pass_input = raw_input("\033[32;1m请输入您的密码:\033[0m") if user_info.get(user_input): if pass_input == user_info[user_input]: #判断用户输入的密码和存储的用户密码是否匹配 return True else: user_info = { "zhangsan":"mima2" user_info = { "zhangsan":"mima3" } user_info = { 18893220999wWWW }wW } return False if pass_input == user_info[user_input]: if user_info.get(user_input): if user_input == user_info[user_input]: if pass_input == user_info[user_input]: if user_info.get == user_info[user_input]: return True else: return False user_info = { return False } if user_info.get == user_info[user_input]: return False else: return False if pass_input == user_info[user_input]: return True: else: return False def wrapper(func) def inner(): if log_auth(): #如果是登录成功返回True然后执行fun函数(func=被装饰的函数) func() else: func3 return "\033[32;1m登录失败\033[0m" return inner def wrapper(func): def inner(): if log_auth(): def wrapper(func): def inner(): if log_auth(): @wrapper def func1(): print "hello This is Func1" def func1(): print "hello this is Func1" @wrapper def func2(): print "hello This is Func2" @wrapper def func3(): print "hello This is Func3" @wrapper def func4(): print "hello This is Func4" @wrapper def func5(): print def func5(): print "hello this is Func5" def func6(): print @wrapper def func7(): print "hello" def func8(): print "hello" def func9(): print "print" func1()
########## 今天的苦逼是为了不这样一直苦逼下去!##########