Skip to content

Instantly share code, notes, and snippets.

@fdb713
Created November 20, 2013 07:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fdb713/7559313 to your computer and use it in GitHub Desktop.
Save fdb713/7559313 to your computer and use it in GitHub Desktop.
xiami.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
File: xiami.py
Author: Luigi Fan
Description: Auto check-in script for xiami.
'''
import requests
import re
import sys
from argparse import ArgumentParser
url_login = 'http://www.xiami.com/web/login'
url_home = 'http://www.xiami.com/web'
data = {
'LoginButton': '登录'
}
headers= {
'Origin': "http://www.xiami.com",
'Referer': 'http://www.xiami.com/web/login',
'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36',
}
if __name__ == '__main__':
if len(sys.argv) < 3:
print "Arguments missing. Usage: python xiami.py email password."
sys.exit(1)
data["email"] = sys.argv[1]
data["password"] = sys.argv[2]
s = requests.Session()
r = s.post(url_login, data=data, headers=headers)
if r.url == url_login:
print "[Failed] Log in failed."
s.close()
sys.exit(1)
c = s.get(url_home, headers=headers)
checkin_pattern = re.compile(r'<a class="check_in" href="(.*?)">')
checkin_button = checkin_pattern.search(c.text)
if checkin_button:
checkin_url = "http://www.xiami.com%s" % checkin_button.group(1)
checkin_response = s.get(checkin_url, headers=headers)
else:
checkin_response = c
checkin_days = re.compile(ur'已连续签到(\d+)天').search(checkin_response.text)
print "[Succeed] Checked in already! %s days." % checkin_days.group(1)
s.close()
@ahxxm
Copy link

ahxxm commented Jan 25, 2015

似乎失效了?我get checkin_url之后返回的还是/web界面,还有签到按钮
手工调试结果是checkin_url后面加上了?spm= ,不知道这是不是验证机制
求测试~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment