刚刚接触python一周左右,之前写了一个python登录人人网的程序成功了(无验证码)。但是登陆教务系统的网站却常常返回一个数据库繁忙的页面至今找不到问题!!请各位大佬帮小弟看看问题出在了哪里。
#!/usr/bin/env Python
# coding=utf-8
import urllib,urllib.request,http.cookiejar
#设置cookie
cookiejar=http.cookiejar.CookieJar()
cookie=urllib.request.HTTPCookieProcessor(cookiejar)
opener=urllib.request.build_opener(cookie,urllib.request.HTTPHandler())
urllib.request.install_opener(opener)
picture = opener.open("http://202.119.113.135/validateCodeAction.do?random=0.9764833140150464").read()
# 用openr访问验证码地址,获取cookie
local = open('C:\\Users\\Administrator\\python program\\picture\\1.png', 'wb')
local.write(picture)
local.close()
v_yzm=input('请输入验证码')
#帐号信息
data={'zjh':'我的帐号',
'mm':'我的密码',
'v_yzm':'v_yzm'}
url='http://202.119.113.135/loginAction.do'
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER",
"Referer":"http://202.119.113.135/loginAction.do",
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding":"gzip, deflate",
"Accept-Language":"zh-CN,zh;q=0.8",
"Cache-Control":"max-age=0",
"Connection":"keep-alive",
"Content-Length":"35",
"Content-Type":"application/x-www-form-urlencoded",
"Cookie":"infoc_client_uuid=e403db584cae35451e982cdb8091a5c8; JSESSIONID=cbffhcwnfuSVBeTEhZX6v",
"Host":"202.119.113.135",
"Origin":"http://202.119.113.135",
"Upgrade-Insecure-Requests":"1",
}
#编码
postdata=urllib.parse.urlencode(data).encode(encoding='UTF8')
#发送请求
req=urllib.request.Request(url,postdata,headers)
#得到源代码
print (opener.open(req).read().decode("gbk"))