Python实现的金山快盘的签到程序

yipeiwu_com5年前Python基础

复制代码 代码如下:

__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()

相关文章

Python中文编码那些事

首先,要明白encode()和decode()的区别  encode()的作用是将Unicode编码的字符串转换为其他编码格式。 例如: st1.encode("utf-8")...

python使用arp欺骗伪造网关的方法

本文实例讲述了python使用arp欺骗伪造网关的方法。分享给大家供大家参考。具体实现方法如下: #coding:utf-8 ''' arp欺骗局域网pc,将伪造的网关mac以网关的...

Python实现可自定义大小的截屏功能

Python实现可自定义大小的截屏功能

本文实例讲述了Python实现可自定义大小的截屏功能。分享给大家供大家参考,具体如下: 蝈蝈这两天正忙着收拾家当去公司报道,结果做PHP的发小蛐蛐找到了他,说是想要一个可以截图工具。 大...

TensorFlow索引与切片的实现方法

TensorFlow索引与切片的实现方法

索引与切片在Tensorflow中使用的频率极其高,可以用来提取部分数据。 1.索引 在 TensorFlow 中,支持基本的[𝑖][𝑗]…标准索引方...

Python面向对象封装操作案例详解 II

Python面向对象封装操作案例详解 II

本文实例讲述了Python面向对象封装操作。分享给大家供大家参考,具体如下: 目标 士兵突击案例 身份运算符 封装 封装 是面向对象编程的一大特点 面向对象编程的 第一步 —— 将 属性...