标签:
其实最想做的是选课插件,于是这次试试了下选课系统,但是选课系统 有验证码。 很是蛋疼。 需要识别。 但是现在可以用另一种方法。就是下载到本地手动输入。也只需要一次就够了。因为登陆成功后就可以随意操作其他东西了。 后面再学习验证码的智能识别。
首先主要是模拟逻辑是。先设置一个cookie存储器,用它去访问验证码链接。然后会得到cookie.还有下载好的验证码图片,就在本地。然后再把验证码,用户名,密码,和那个cookie一起提交到登陆。于是cookie就一致了。 有点不舒服的就是需要在本地看下那个图片长什么样,然后再输入控制台。具体代码是:
#!usr/bin/env python
#-*- coding: utf-8 -*-
import os
import urllib2
import urllib
import cookielib
import re
Img_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 IOError:
print 'file wrong'
#input code
img_code=raw_input("please input code: ")
print 'your code is %s'%img_code
#login
LoginData = {
'Login.Token1':username,
'Login.Token2':password,
'verifyCode':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.read())
fout.close()
#load class info
print 'load class'
fout=open('t1.html','w')
fout.write(opener.open(Class_URL).read())
fout.close()
if __name__=='__main__':
login()Python模拟登陆3: 进入选课系统(手工输入验证码阶段)
标签:
原文地址:http://blog.csdn.net/cq361106306/article/details/42611117