Python analog Dragon Net login with verification code input

Source: Internet
Author: User

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

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.