Python Simulation Login: Simulation login UESTC Information portal test

Source: Internet
Author: User

Recently in the network operation of learning Python, there are a lot of analog landing methods on the Internet. Take a note here. It is easier to do without a verification code.

#coding: Utf-8import reimport urllibimport urllib2import cookielibimport osimport jsonimport sysimport timefrom urllib Import quote,unquotefrom urllib2 import httperrorfrom urllib2 import urlerror# login Module def login (): TRY:CJ = Cookie Lib.        Cookiejar (); Opener = Urllib2.build_opener (urllib2.        Httpcookieprocessor (CJ));                 Urllib2.install_opener (opener); #打开获得 Cookie Info_url = "Http://portal.uestc.edu.cn/index.portal" Info_login_url = "https://uis.uestc.edu.cn             /amserver/ui/login ";            Infoopen = Urllib2.urlopen (info_url) Print 1 #生成要发送的数据 logindata = {' IDToken0 ': ', ' IDToken1 ': ' 20142106XXXX ', ' IDToken2 ': ' xxxxxx ', ' Idbutton ': ' Submit ', ' goto ': ' Ahr0cdo Vl3bvcnrhbc51zxn0yy5lzhuuy24vbg9naw4ucg9ydgfs ', ' encoded ': ' true ', ' gx_charset ': ' UTF-8 ',}                 ; Print 2 #把发送数据转换格式 logindata = Urllib.urlencode (logiNdata); #生成请求数据 info_login_request = urllib2.                Request (Info_login_url, logindata);        #添加数据头部 info_login_request.add_header (' Content-type ', "application/x-www-form-urlencoded"); Info_login_request.add_header (' user-agent ', "mozilla/5.0 (X11;        Linux i686) applewebkit/537.36 (khtml, like Gecko) chrome/39.0.2171.95 safari/537.36 ");        Print 3 #发送请求, try logging in Info_login_open = Urllib2.urlopen (info_login_request); Print 4 #验证登陆是否成功 TT = Urllib2.urlopen (info_url). Read () Fout=open ("Tt.html", "W") Fout.write (TT    ) print ' success! ' Except:print "Landing Error! "If __name__ = =" __main__ ": Login ()

Tested successfully

IDtoken1 and IDtoken2 fill in the user name and password. Others do not change

Linux directly below the Python spider.py can be run

Python Simulation Login: Simulation login UESTC Information portal test

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.