複製代碼 代碼如下:__author__ = 'clownfish'
#coding:utf-8
import urllib2,urllib,cookielib,json
username = "快盤使用者名稱"
password = "快盤密碼"
class sign(object):
username = ''
password = ''
#登入顯示頁面
indexurl = 'https://www.kuaipan.cn/account_login.htm'
#登入的form表單url
loginurl = 'https://www.kuaipan.cn/index.php?ac=account&op=login'
#簽到的真正url
signurl = 'http://www.kuaipan.cn/index.php?ac=common&op=usersign'
def __init__(self,username,password):
self.username = username
self.password = password
def login(self):
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
print "開啟登入頁面"
try:
urllib2.urlopen(self.indexurl)
post_data = {'username':self.username,'userpwd':self.password,'isajax':'yes'}
req=urllib2.Request(self.loginurl,urllib.urlencode(post_data))
except Exception, e:
print "網路連結錯誤"
return False
print "登入成功,準備簽到!"
response = urllib2.urlopen(req)
login=response.read()
return login
def sign(self):
response = urllib2.urlopen(self.signurl)
sign = response.read()
l = json.loads(sign)
if (l and l['state'] == 1) or \
(l and 0 == l['state'] and l['increase'] * 1 == 0 and l['monthtask'].M900 == 900):
print "恭喜你簽到成功!"
k = l['increase']*1
m = l['rewardsize'] * 1
if (k == 0 and l['monthtask'].M900 == 900):
print "本月簽到積分已領取完成"
else:
print "簽到獎勵積分:%s" % (k)
if m == 0:
print "手氣太不好了!獎勵 0M 空間"
else:
print "簽到獎勵空間:%s" % (m)
else:
if (l['state'] == -102):
print "今天您已經簽到過了"
else:
print "簽到失敗,遇到網路錯誤,請稍後再試!"
return sign
if __name__ == "__main__":
sign = sign(username,password)
if sign.login():
sign.sign()