Python(Tornado)模擬登錄小米搶手機(jī)
更新時(shí)間:2013年11月12日 09:18:41 作者:
用Python(Tornado)模擬登錄小米帳號(hào),搶小米手機(jī)
今天看到同事參與小米的搶購,幾經(jīng)數(shù)個(gè)星期的嘗試,終于搶到了一臺(tái)小米電視……看了一下小米的搶購流程,似乎可以用程序可破。于是想寫點(diǎn)東西玩玩(你懂的……),第一步肯定是先得模擬登錄小米帳號(hào),當(dāng)練手吧。
用 Python 來實(shí)現(xiàn)吧,由于是寫一個(gè)Web應(yīng)用,那么框架就選 Tornado。
首先是定義應(yīng)用的 URL:
def main():
tornado.options.parse_command_line()
application = tornado.web.Application([
(r"/", MainHandler),
(r"/mibuy/", MiBuyHandler),
],**settings)
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
接下來就是尋找需要 post 過去的數(shù)據(jù),用 Fiddler 來嗅探一下:

也就是說,POST 的地址是 https://account.xiaomi.com/pass/serviceLoginAuth2

需要構(gòu)造的表單參數(shù)也很簡單(已進(jìn)行 URL 編碼):passToken=&user=www.nowamagic.net&pwd=password&callback=https%3A%2F%2Faccount.xiaomi.com&sid=passport&qs=%253Fsid%253Dpassport&hidden=&_sign=KKkRvCpZoDC%2BgLdeyOsdMhwV0Xg%3D。即:
post_data = urllib.urlencode({'passToken':'', 'user': 'www.nowamagic.net', 'pwd': 'password', 'callback':'https://account.xiaomi.com', 'sid':'passport', 'qs':'%3Fsid%3Dpassport', 'hidden':'', '_sign':'KKkRvCpZoDC+gLdeyOsdMhwV0Xg='})
path = 'https://account.xiaomi.com/pass/serviceLoginAuth2'
接下來函數(shù)也可以寫出來了:
class MiBuyHandler(tornado.web.RequestHandler):
def get(self):
cj = cookielib.CookieJar()
post_data = urllib.urlencode({'passToken':'', 'user': 'www.nowamagic.net', 'pwd': 'password', 'callback':'https://account.xiaomi.com', 'sid':'passport', 'qs':'%3Fsid%3Dpassport', 'hidden':'', '_sign':'KKkRvCpZoDC+gLdeyOsdMhwV0Xg='})
path = 'https://account.xiaomi.com/pass/serviceLoginAuth2'
cookieHandle = urllib2.HTTPCookieProcessor(cj)
opener = urllib2.build_opener(cookieHandle)
#opener.addheaders = [('User-agent', 'Opera/9.23')]
urllib2.install_opener(opener)
req = urllib2.Request(path, post_data)
response = urllib2.urlopen(req)
html = response.read()
self.render("mibuy.html",message=html)
如何需要把 cookie 打印出來,直接 print cj 就可以看到 cookie 的內(nèi)容。
接下來的事情貌似也很簡單,就是解析 hdcontrol (URL:http://tc.hd.xiaomi.com/hdget?callback=hdcontrol) 這個(gè) json。
hdcontrol(
{
stime: 1383645496,
status: {
allow: true,
miphone: {
hdurl: "",
duration: null,
hdstop: true,
reg: true,
pmstart: false,
hdstart: false
},
mibox: {
hdurl: "",
duration: null,
hdstop: true,
reg: true,
pmstart: false,
hdstart: false
},
mitv: {
hdurl: "",
duration: null,
hdstop: true,
reg: false,
pmstart: false,
hdstart: false
}
}
})
當(dāng) allow 為 true 的時(shí)候,hdurl 會(huì)有值,比如 ?_a=20131105_phone_a212a2b30e5&_op=choose&_s=72b686828&_m=1 之類的,這個(gè)就是真實(shí)的搶購地址,直接訪問這個(gè)地址應(yīng)該就不用再點(diǎn)排隊(duì)的按鈕。僅當(dāng)拋磚引玉,懂程序的各位都該知道怎么辦了吧……
僅僅適用于目前(2013年11月),后續(xù)小米那邊可能會(huì)改變一些規(guī)則。
用 Python 來實(shí)現(xiàn)吧,由于是寫一個(gè)Web應(yīng)用,那么框架就選 Tornado。
首先是定義應(yīng)用的 URL:
復(fù)制代碼 代碼如下:
def main():
tornado.options.parse_command_line()
application = tornado.web.Application([
(r"/", MainHandler),
(r"/mibuy/", MiBuyHandler),
],**settings)
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
接下來就是尋找需要 post 過去的數(shù)據(jù),用 Fiddler 來嗅探一下:

也就是說,POST 的地址是 https://account.xiaomi.com/pass/serviceLoginAuth2

需要構(gòu)造的表單參數(shù)也很簡單(已進(jìn)行 URL 編碼):passToken=&user=www.nowamagic.net&pwd=password&callback=https%3A%2F%2Faccount.xiaomi.com&sid=passport&qs=%253Fsid%253Dpassport&hidden=&_sign=KKkRvCpZoDC%2BgLdeyOsdMhwV0Xg%3D。即:
復(fù)制代碼 代碼如下:
post_data = urllib.urlencode({'passToken':'', 'user': 'www.nowamagic.net', 'pwd': 'password', 'callback':'https://account.xiaomi.com', 'sid':'passport', 'qs':'%3Fsid%3Dpassport', 'hidden':'', '_sign':'KKkRvCpZoDC+gLdeyOsdMhwV0Xg='})
path = 'https://account.xiaomi.com/pass/serviceLoginAuth2'
接下來函數(shù)也可以寫出來了:
復(fù)制代碼 代碼如下:
class MiBuyHandler(tornado.web.RequestHandler):
def get(self):
cj = cookielib.CookieJar()
post_data = urllib.urlencode({'passToken':'', 'user': 'www.nowamagic.net', 'pwd': 'password', 'callback':'https://account.xiaomi.com', 'sid':'passport', 'qs':'%3Fsid%3Dpassport', 'hidden':'', '_sign':'KKkRvCpZoDC+gLdeyOsdMhwV0Xg='})
path = 'https://account.xiaomi.com/pass/serviceLoginAuth2'
cookieHandle = urllib2.HTTPCookieProcessor(cj)
opener = urllib2.build_opener(cookieHandle)
#opener.addheaders = [('User-agent', 'Opera/9.23')]
urllib2.install_opener(opener)
req = urllib2.Request(path, post_data)
response = urllib2.urlopen(req)
html = response.read()
self.render("mibuy.html",message=html)
如何需要把 cookie 打印出來,直接 print cj 就可以看到 cookie 的內(nèi)容。
接下來的事情貌似也很簡單,就是解析 hdcontrol (URL:http://tc.hd.xiaomi.com/hdget?callback=hdcontrol) 這個(gè) json。
復(fù)制代碼 代碼如下:
hdcontrol(
{
stime: 1383645496,
status: {
allow: true,
miphone: {
hdurl: "",
duration: null,
hdstop: true,
reg: true,
pmstart: false,
hdstart: false
},
mibox: {
hdurl: "",
duration: null,
hdstop: true,
reg: true,
pmstart: false,
hdstart: false
},
mitv: {
hdurl: "",
duration: null,
hdstop: true,
reg: false,
pmstart: false,
hdstart: false
}
}
})
當(dāng) allow 為 true 的時(shí)候,hdurl 會(huì)有值,比如 ?_a=20131105_phone_a212a2b30e5&_op=choose&_s=72b686828&_m=1 之類的,這個(gè)就是真實(shí)的搶購地址,直接訪問這個(gè)地址應(yīng)該就不用再點(diǎn)排隊(duì)的按鈕。僅當(dāng)拋磚引玉,懂程序的各位都該知道怎么辦了吧……
僅僅適用于目前(2013年11月),后續(xù)小米那邊可能會(huì)改變一些規(guī)則。
相關(guān)文章
Python異步在非阻塞子進(jìn)程中運(yùn)行命令詳解
這篇文章主要為大家介紹了Python異步在非阻塞子進(jìn)程中運(yùn)行命令詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03一文教你用Python中progress庫實(shí)現(xiàn)進(jìn)度條
這篇文章主要為大家詳細(xì)介紹了如何通過Python中的progress庫實(shí)現(xiàn)進(jìn)度條的繪制,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-03-03Python數(shù)據(jù)結(jié)構(gòu)之列表與元組詳解
序列是Python中最基本的數(shù)據(jù)結(jié)構(gòu)。序列中的每個(gè)元素都分配一個(gè)數(shù)字 - 它的位置,或索引,第一個(gè)索引是0,第二個(gè)索引是1,依此類推,元組與列表類似,不同之處在于元組的元素不能修改。元組使用小括號(hào),列表使用方括號(hào)2021-10-10windows下Python實(shí)現(xiàn)將pdf文件轉(zhuǎn)化為png格式圖片的方法
這篇文章主要介紹了windows下Python實(shí)現(xiàn)將pdf文件轉(zhuǎn)化為png格式圖片的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Python實(shí)現(xiàn)將pdf轉(zhuǎn)換為png格式的相關(guān)模塊、使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-07-07如何將Pycharm中Terminal使用Powershell作為終端
這篇文章主要介紹了如何將Pycharm中Terminal使用Powershell作為終端問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05基于Python編寫一個(gè)圖片識(shí)別系統(tǒng)
本項(xiàng)目將使用python3去識(shí)別圖片是否為色情圖片,會(huì)使用到PIL這個(gè)圖像處理庫,并且編寫算法來劃分圖像的皮膚區(qū)域,感興趣的可以了解一下2022-06-06python實(shí)現(xiàn)微信遠(yuǎn)程控制電腦
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)微信遠(yuǎn)程控制電腦的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02