First of all, I would like to thank longchang for automatically signing in to the Kingsoft disk at http://www.oschina.net/code/snippet_93572_000021.pdfProgramCodeOn this basis, I made a program using wxpython. The specific code is as follows:
# -*-Coding: cp936 -*- # '@ Xiaowuyi http://www.cnblogs.com' # 'Kingsoft fast disk sign-In Process' Import Urllib Import Urllib2 Import Cookielib Import JSON Import Re Import WX Def Create (parent ): Return Frame1 (parent) [wxid_frame1, wxid_frame1button1, wxid_frame1panel1, struct, wxid_frame1statictext2, wxid_frame1statictext3, struct, struct,] = [Wx. newid () For _ Init_ctrls In Range (8 )] Class Frame1 (wx. Frame ): Def _ Init_ctrls (self, prnt ): # Generated method, Don't edit Wx. Frame. _ Init __ (Self, id = wxid_frame1, name = '' , Parent = Prnt, POS = Wx. Point (529,321), size = wx. Size (400,250 ), Style = Wx. system_menu | wx. minimize_box | wx. close_box | Wx. Caption, title = ' Kingsoft drive automatic sign-In V1.0 ' ) Self. setclientsize (wx. Size ( 392,216 ) Self. Panel1 = Wx. Panel (ID = wxid_frame1panel1, name = ' Panel1 ' , Parent = Self, POS = Wx. Point (0, 0), size = wx. Size (392,216 ), Style = Wx. tab_traversal) self. statictext1 = Wx. statictext (ID = Wxid_frame1statictext1, label =' User name: ' , Name = ' Statictext1 ' , Parent = Self. Panel1, POS = Wx. Point (8, 16), size = wx. Size (95, 23), style = 0) self. statictext1.setfont (wx. Font ( 14 , Wx. Swiss, wx. Normal, wx. Bold, false, u ' Tahoma ' ) Self. statictext2 = Wx. statictext (ID =Wxid_frame1statictext2, label = ' Password: ' , Name = ' Statictext2 ' , Parent = Self. Panel1, POS = Wx. Point (8, 56), size = wx. Size (92, 23), style = 0) self. statictext2.setfont (wx. Font ( 14 , Wx. Swiss, wx. Normal, wx. Bold, false, u ' Tahoma ' ) Self. textctrl1 = Wx. textctrl (ID = wxid_frame1textctrl1, name = ' Textctrl1 ' , Parent = Self. Panel1, Pos = wx. Point (112, 16), size = wx. Size (176, 24 ), Style = 0, value = '' ) Self. textctrl2 = Wx. textctrl (ID = wxid_frame1textctrl2, name = ' Textctrl2 ' , Parent = Self. Panel1, Pos = wx. Point (112, 56), size = wx. Size (176, 22 ), Style = Wx. te_password, value = '' ) Self. button1 = Wx. Button (ID = wxid_frame1button1, label = ' Sign in ' , Name = ' Button1 ' , Parent = self. Panel1, Pos = wx. Point (304, 56 ), Size = Wx. Size (75, 24), style =0) self. button1.bind (wx. evt_button, self. onbutton1button, ID = Wxid_frame1button1) self. statictext3 = Wx. statictext (ID = Wxid_frame1statictext3, label = ' Sign-in status ...... ' , Name = ' Statictext3 ' , Parent = Self. Panel1, POS = Wx. Point (16,104), size = wx. Size (352, 96), style = 0) self. statictext3.setfont (wx. Font ( 12 , Wx. Swiss, wx. Normal, wx. Bold, false, u ' Tahoma ' ) Self. button1.bind (wx. evt_button, self. onbutton1button, ID = Wxid_frame1button1) CJ = Cookielib. cookiejar () self. Opener = Urllib2.build _ opener (urllib2.httpcookieprocessor (CJ) urllib2.install _ opener (self. opener) self. opener. addheaders = [( ' User-Agent ' , ' IE ' )] Def _ Init __ (Self, parent): Self. _ init_ctrls (parent) Def Login (self, username, password): URL = ' Https://www.kuaipan.cn/index.php? AC = Account & OP = Login ' Data = Urllib. urlencode ({ ' Username ' : Username, ' Userpwd ' : Password}) req = Urllib2.request (URL, data) Try : FD = Self. opener. Open (req) Except Exception, E: Self. statictext3.setlabel ( ' Network Connection error! ' ) Return False If FD. url! = " Http://www.kuaipan.cn/home.htm " : Self. statictext3.setlabel ( " The username and password do not match! " ) Return False self. statictext3.setlabel ( ' % S login successful ' % Username ), Return True Def Logout (Self): URL = ' Http://www.kuaipan.cn/index.php? AC = Account & OP = logout ' REQ = Urllib2.request (URL) FD =Self. opener. Open (req) FD. Close () Def Sign (Self): URL = ' Http://www.kuaipan.cn/index.php? AC = Common & OP = usersign ' REQ = Urllib2.request (URL) FD = Self. opener. Open (req) sign_js = JSON. Loads (FD. Read ()) # Print sign_js Tri = Self. statictext3.getlabel (). encode ( ' Cp936 ' ) If Sign_js [ ' State ' ] =-102 : Self. statictext3.setlabel (Tri + ' \ N ' + " Signed today! " ) Elif Sign_js [ ' State ' ] = 1 : Self. statictext3.setlabel (Tri + ' \ N ' + " Sign-in successful! \ N points: % d, total points: % d; \ n Space: % DM \ n " % (Sign_js [ ' Increase ' ], Sign_js [ ' Status ' ] [ ' Points ' ], Sign_js [ ' Rewardsize ' ]) Else : Self. statictext3.setlabel (Tri + ' \ N ' + " Failed to sign in! " ) FD. Close () Def Onbutton1button (self, event): Self. statictext3.setlabel ( '' ) Namew = Self. textctrl1.getvalue (). encode ( ' Cp936 ' ) Passw = Self. textctrl2.getvalue (). encode ( ' Cp936 ' ) If Self. login (namew, passw) = True: Self. Sign () self. logout () # Event. Skip () Class APP (wx. app ): Def Oninit (Self): Self. Main = Create (none) self. Main. Show () self. settopwindow (self. Main) Return True Def Main (): Application = APP (0) application. mainloop () If _ Name __ = ' _ Main __ ' : Main ()
@ Xiaowuyi http://www.cnblogs.com/xiaowuyi