新博客地址:http://gorthon.sinaapp.com/
【注意】中国移动官网只能查询到无线上网的清单。如果你开通了中国移动的有线上网的话,这个是查不到的,因为我没找到官网上有查询有线使用多少小时以及清单的地方,所以这个只能查询无线上网的清单。有线的在哪里查询,找到的同学告诉一下啊。
# _*_ encoding:gbk _*_ import re import urllib2 import urllib import hashlib import cookielib import os import random from subprocess import Popen import datetime class ChinaMobile: def __init__(self, number='', pwd=''): self.number = number self.pwd = pwd self.cookie = cookielib.LWPCookieJar('%s' % self.number[3:]) self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie)) self.opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.3) / #Gecko/20100401 Firefox/3.6.3')] urllib2.install_opener(self.opener) def get(self, url): return self.opener.open(urllib2.Request(url)).read() def post_str(self, url, params=''): return self.opener.open(urllib2.Request(url, params)).read() def main(): phone_number = '手机号码' pwd = '登录密码' m = ChinaMobile(phone_number, pwd) r = str(random.random()) + str(random.randrange(9))*4 file('./verifycode.jpg', 'wb').write(m.get('http://service.js.10086.cn/js_obsh_service/imageVerifyCode?t=new&r=%s'%r)) Popen("mspaint.exe .//verifycode.jpg", 0, None, None, None, None ) # 这里是用的windows的,下次补上linux的 verify_code = raw_input('输入验证码(不区分大小写):').strip() login = m.post_str('http://service.js.10086.cn/js_obsh_service/actionDispatcher.do',/ 'jsonParam=[{"dynamicURI":"/login","dynamicParameter":{"method":"login",/ "userMobile":"%s","pwd":"%s","verifyCode":"%s","loginType":"1","loginCity":"NJDQ"},/ "dynamicDataNodeName":"loginNode2"}]'/ %(phone_number, pwd, verify_code)) # 这里的参数可能不同省份不同(上面这个是南京的) if re.search(phone_number, login) == None: print '验证码错误,请重试。/n' return True now = str(datetime.datetime.now()).replace('-', '').replace(' ', '').replace(':', '')[:14] query_month = now[:6] end_date = now[6:8] post_str = 'jsonParam=[{"dynamicURI":"/accountBusiness","dynamicParameter":/ {"method":"getFeelListDetail","busiNum":"QDCX","queryType":"WLANQD","queryMonth":"%s",/ "startDate":"01","endDate":"%s","queryFilterMobile":""},"dynamicDataNodeName":/ "qdcxdetailBusinessNode"}]' % (query_month, end_date) wlan_fee = m.post_str('http://service.js.10086.cn/js_obsh_service/actionDispatcher.do', post_str) seconds = sum(map(int, re.findall('callDuration":"(/d*)"',wlan_fee))) left = 180000 - seconds hours = seconds / 3600 seconds = seconds % 3600 minutes = seconds / 60 seconds = seconds % 60 print '/n已用: %i 时 %i 分 %i 秒' % (hours, minutes, seconds) seconds = left hours = seconds / 3600 seconds = seconds % 3600 minutes = seconds / 60 seconds = seconds % 60 print '/n剩余: %i 时 %i 分 %i 秒' % (hours, minutes, seconds) raw_input('/n/n回车键退出..') return False if __name__ == '__main__': while(main()): pass
就懒得打包成exe了……