Last active
August 29, 2015 14:24
-
-
Save wong2/01b0ad9d29558713dcc2 to your computer and use it in GitHub Desktop.
遍历友宝免费冰红茶兑换码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #-*-coding:utf-8-*- | |
| import re | |
| import time | |
| import json | |
| import requests | |
| from random import choice | |
| code_url = 'http://ama.adwo.com/advmessage/adv/addResultJsonP.action?advid=30345&mobile={phone}&callback=callback' | |
| result_url = 'http://ama.adwo.com/advmessage/advtrophcsf/awardJsonP.action?advid=30345&userinfo={phone}&resultid={result_id}&callback=callback' | |
| headers = {'Referer': 'http://static.adwo.com/ad/201506/ksficetea/index.html'} | |
| fp = open('nums.txt', 'a') | |
| def parse_result(s): | |
| json_str = re.search('callback\((.*)\)', s).group(1) | |
| resp = json.loads(json_str)[0] | |
| return resp | |
| def get_code(phone): | |
| r = requests.get(code_url.format(phone=phone), headers=headers) | |
| resp = parse_result(r.text) | |
| success = resp['success'] | |
| if success != 1: | |
| print 'failed' | |
| return | |
| result_id = resp['id'] | |
| r = requests.get(result_url.format(phone=phone, result_id=result_id), headers=headers) | |
| resp = parse_result(r.text) | |
| if resp['award'] == 0: | |
| print 'no luck' | |
| return | |
| num = resp['ubox']['data']['cardNum'] | |
| print 'got ', num | |
| fp.write('%s\n' % num) | |
| fp.flush() | |
| if __name__ == '__main__': | |
| while True: | |
| phone = choice(['139','188','185','136','158','151']) + "".join(choice("0123456789") for _ in range(8)) | |
| print phone | |
| get_code(phone) | |
| time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment