python模拟登录教务系统_python requests库模拟登陆学校教务网遇到数据库繁忙

第一次写爬虫也是第一次在SF提问题=。=

思路就是get登陆下网址获得一个cookie然后带着cookie以post方式登陆

headers伪造和浏览器一模一样

服务器总是返回一个数据库繁忙的界面,找了很久也不知道原因在哪

s = requests.Session()

x = s.get(loginUrl)

r = s.post(postUrl,data=

{

'zjh':'********',

'mm':'********',

'v_yzm':CodeRecognition()

}

,headers = headers)

print(x.headers)

print(x.request.headers)

print(r.headers)

print(r.request.headers)

f=file("cookie.txt","w+")

f.write(r.text)

f.close()

CodeRecognition() 这个验证码识别模块源码太长就不贴出来了,就是先用urllib库访问验证码地址 http://222.195.242.222:8080/validateCodeAction.do 把图片下载到本地,然后对图像二值化灰度等处理后调用Tesseract-OCR识别并返回

补充内容:在chrome中用EditThisCookie管理工具删掉网站的cookie然后刷新页面,登录会失败,返回数据库繁忙。但是我用session先访问网站返回给了我一个setcookie,然后带着这个cookie post表单为什么还是会有这个错误呢?

这是在sublime3中运行打印出的内容:

{'Transfer-Encoding': 'chunked', 'Set-Cookie': 'JSESSIONID=bhazvcnoUA-YYbw_WQZsv; path=/', 'Keep-Alive': 'timeout=8, max=500', 'Server': 'Apache', 'Connection': 'Keep-Alive', 'Cache-Control': 'private', 'Date': 'Sun, 15 May 2016 09:06:53 GMT', 'Content-Type': 'text/html; charset=GBK'}

{'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.9.1'}

{'Transfer-Encoding': 'chunked', 'Keep-Alive': 'timeout=8, max=499', 'Server': 'Apache', 'Connection': 'Keep-Alive', 'Date': 'Sun, 15 May 2016 09:06:53 GMT', 'Content-Type': 'text/html; charset=GBK'}

{'Origin': 'http://222.195.242.222:8080', 'Content-Length': '77', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'keep-alive', 'Accept': '*/*', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.82 Safari/537.36', 'Host': '222.195.242.222:8080', 'Referer': 'http://222.195.242.222:8080/', 'Cookie': 'JSESSIONID=bhazvcnoUA-YYbw_WQZsv', 'Content-Type': 'application/x-www-form-urlencoded'}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值