java 小米抢购_Github搞得小米抢购脚本,参考一下

# -*- coding:utf-8 -*-

#读取小米账号

import urllib2

import urllib

import cookielib

class Xiaomi:

'''小米抢购'''

def __init__(self,filename):

#读取名为filename的文件

self.file=open(filename)

#print(self.file)

def reader_user(self):

xmfile=self.file

print(xmfile)

for line in xmfile.xreadlines():

pass

string=line.lstrip().split('----')

#print(string)

if(len(string) != 2):

print("帐号格式错误,请使用4个-作为分隔符")

userName=string[0]

password=string[1]

self.login(userName,password)

def login(self,userName,password):

#登陆页面,通过抓包工具分析获得,如fiddler

login_url="https://account.xiaomi.com/pass/serviceLoginAuth2"

try:

#得到一个cookieJar实例

cj=cookielib.CookieJar()

#获得一个opener实例

opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

#伪装成firefox浏览器,

opener.addheaders=[('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0')]

#生成post数据,包含登录信息

data = urllib.urlencode({'passToken':'', 'user': userName, 'pwd': password, 'callback':'https://account.xiaomi.com', 'sid':'passport', 'qs':'%3Fsid%3Dpassport', 'hidden':'', '_sign':'KKkRvCpZoDC+gLdeyOsdMhwV0Xg='})

#设置urllib2的全局opener,建议使用open

urllib2.install_opener(opener)

#data参数传到Request对象

req = urllib2.Request(login_url, data)

#接受一个request对象,返回一个像文件对象一样的对象

op = urllib2.urlopen(req)

#读取页面源码

html=op.read()

#print(html)

self.buying()

except Exception,e:

print str(e)

def buying(self):

buy_url="http://www.mi.com/buyphone/mi3"

try:

req = urllib2.Request(buy_url)

op=urllib2.urlopen(req)

#读取页面代码

html=op.read()

print(html)

except Exception,e:

print str(e)

print("成功")

xm=Xiaomi('xiaomi.txt')

xm.reader_user()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值