python的签到脚本

一到周末就忘记签到,改编一段脚本,应该可以放到香蕉的计划任务中,至于怎么放还要学习,稍后补充

# -*- coding: utf-8 -*-
import urllib2
import urllib
import sys

def login(username, password):
    try:
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
        opener.open("http://mikuq.com/login").read()
        post_data = "uid=%s&pwd=%s" % (username, password)
        data = opener.open("http://mikuq.com/login", post_data).read()
        
        if data.decode("utf-8").find(u"退出登录") == -1:
            return None
        return opener
    except:
        return None

opener = login("uid", "pwd")
if not opener:
    print("fail")
else:
    print "ok"
    content = opener.open("http://mikuq.com/signin").read()
    print content.decode("gbk")

sudo vi /etc/crontab
5 0 * * * root python /home/pi/py/qiandao.py
00:05签到,不过还是第7名,再提前一些00:02吧

标签: none

添加新评论