Python Simulation Login 3: Enter the course selection system (manually enter the verification code stage)

Source: Internet
Author: User

In fact, the most want to do is to choose the class plug-in, so this time to try to choose the course system, but the course selection system has a verification code. It's a sore egg. needs to be identified. But now you can use another method. is to download to local manual input. It only takes one time to be enough. Because the landing is successful, you can manipulate other things at will. Later, the intelligent identification of verification code is learned.

The first is primarily analog logic. First set up a cookie memory, use it to access the verification Code link. Then you get a cookie. There is also a download good captcha image, on the local. Then submit the verification Code, username, password, and the cookie to the login. So the cookie is consistent. A bit uncomfortable is the need to see what the image looks like in the local, and then enter the console. The specific code is:

#!usr/bin/env python#-*-coding:utf-8-*-import osimport urllib2import urllibimport cookielibimport reImg_URL= '/http Gs.uestc.edu.cn/wsxk/verifycodegenservlet.do ' login_url= ' http://gs.uestc.edu.cn/wsxk/login.jsp ' class_url= ' http ://gs.uestc.edu.cn/wsxk/jsp/t_pygl_kwgl_wsxk_kxkc.jsp ' username= ' xxxx ' password= ' xxxx ' def login (): CJ = Cookielib. Cookiejar () opener = Urllib2.build_opener (urllib2. Httpcookieprocessor (CJ)) Urllib2.install_opener (opener) #get img img_req=urllib2. Request (Img_url) img_response=opener.open (img_req) try:out=open (' Code ', ' WB ') #print Img_response.read () Out.write (Img_response.read ()) Out.flush () out.close () print ' Get Code success ' except I Oerror:print ' file wrong ' #input code img_code=raw_input ("Please input code:") print ' Your code is%s '%i Mg_code #login logindata = {' Login.token1 ': username, ' login.token2 ':p assword, ' ver        Ifycode ': Img_code,    }; Login_req = Urllib2.    Request (Login_url, Urllib.urlencode (Logindata)); Login_req.add_header (' user-agent ', "mozilla/5.0 (X11;    Linux i686) applewebkit/537.36 (khtml, like Gecko) chrome/39.0.2171.95 safari/537.36 "); Login_response=opener.open (login_req) print ' Login success ' Fout=open ("tt.html", "W") Fout.write (login_response.re AD ()) Fout.close () #load class info print ' Load class ' Fout=open (' t1.html ', ' W ') Fout.write (Opener.open (Clas S_url). Read ()) Fout.close () if __name__== ' __main__ ': Login ()


Python Simulation Login 3: Enter the course selection system (manually enter the verification code stage)

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.