Python (Tornado) analog login Millet grab mobile phone _python

Source: Internet
Author: User
Tags urlencode
Today, I saw my colleagues to participate in the buying of millet, after several weeks of trying to finally grab a millet TV ... Look at the buying process of millet, seems to be able to use the program can be broken. So I wanted to write something to play (you know ...). ), the first step must be a simulated login millet account, when the practicing bar.
With Python, because it's a Web application, the framework chooses Tornado.
The first is the URL that defines the application:
Copy Code code as follows:

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 ()

The next step is to look for the data that needs to be post, and sniff it with Fiddler:

In other words, the address of the POST is Https://account.xiaomi.com/pass/serviceLoginAuth2

The form parameters that need to be constructed are also simple (URL-coded): passtoken=&user=www.nowamagic.net&pwd=password&callback=https%3a%2f% 2faccount.xiaomi.com&sid=passport&qs=%253fsid%253dpassport&hidden=&_sign=kkkrvcpzodc% 2bgldeyosdmhwv0xg%3d. That
Copy Code code as follows:

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 '

The next function can also be written:
Copy Code code as follows:

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)

How to print the cookie, direct print CJ can see the contents of the cookie.
The next thing seems very simple, is parsing Hdcontrol (Url:http://tc.hd.xiaomi.com/hdget?callback=hdcontrol) this JSON.
Copy Code code as follows:

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
}
}
})

When Allow is true, Hdurl will have a value, such as a _a=20131105_phone_a212a2b30e5&_op=choose&_s=72b686828&_m=1 or something, This is the real snapped up address, the direct access to this address should not have to click the line button. Only when the idea, understand the procedure you should know how to do it ...
Only for the present (November 2013), the subsequent millet side may change some rules.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.