1. Using Urllib and URLLIB2 packages
2. Use Cookielib to automatically manage cookies
3.360 Browser F12 grabbing information
Login request address and Verification code address all got it.
#-*-coding:utf-8-*-ImportUrllib2ImportUrllibImportCookielib" "idea: 1. Download the captcha image to local 2 by using a Cookie object. Manually fill in the Verification Code 3. Login 4. Get the login information returned" "#bind a cookie to an object Opener,cookie automatically managed by CookielibCookie =Cookielib. Cookiejar () handler=Urllib2. Httpcookieprocessor (cookie) opener=Urllib2.build_opener (handler)#Verification code URL and login URLCodeurl ='Https://secure.elong.com/passport/getValidateCode'loginurl='Https://secure.elong.com/passport/ajax/elongLogin'#download images to d:/test.gif according to the CAPTCHA addressPicture =Opener.open (Codeurl). Read () Local= Open ('D:/test.gif','WB') local.write (picture) local.close ()#Open This Verification code picture, fill in the Verification codeCodepic = Raw_input ('input please:')#log in to post Fromdata dataPostData = {'UserName':'13718651238', 'passwd':'abcdef0120', 'Validatecode': Codepic,'RememberMe':'false'}#gets the header informationheaders = {'Accept':'*/*','Accept-language':'zh-cn,zh;q=0.8','Connection':'keep-alive','Content-type':'application/x-www-form-urlencoded; Charset=utf-8','user-agent':'mozilla/5.0 (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/45.0.2454.101 safari/537.36',}data= Urllib.urlencode (postdata)#convert data to Key1&value&key2&valueRequest = Urllib2. Request (Loginurl,data,headers)#initiating a login requestResponse = Opener.open (Request)#Gets the response information based on the cookie object that was first acquiredresult = Response.read ()#ReadPrintResult
Execute, manually enter the verification code, success information:
Python analog Dragon Net login with verification code input