python2 爬虫爬教务管理,还有验证码识别
2017-01-13 21:33
716 查看
# -*- coding: utf-8 -*- # ********************************* # vresion:python 2 # author:张琼 # 西北农林科技大学 计算机141 # ********************************* #from urllib import request,parse import cookielib import urllib import urllib2 import re import io from PIL import Image import pytesseract #模拟登录测试模块 print('loging info my ssfw') cookie=cookielib.CookieJar()#储存获取到的cookie opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie)) CaptchaUrl = "http://jwgl.nwsuaf.edu.cn/academic/getCaptcha.do" #验证码图片URL picture = opener.open(CaptchaUrl).read() local = open('e:/image1.jpg', 'wb') local.write(picture) #验证码图片保存下来 local.close() img=Image.open('e:/image1.jpg') vcode = pytesseract.image_to_string(img)#验证码识别 print(vcode) #SecretCode = input('输入验证码: ') #自己查看图片然后输入 SecretCode=vcode print(SecretCode) loging_data=urllib.urlencode([ ('j_username',"20140xxxxxx"), ('j_password',"xxxxxx"), ('j_captcha',SecretCode)])#POST用到的数据 #请求头 headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 '+ '(KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36' } #构造request req=urllib2.Request(url='http://jwgl.nwsuaf.edu.cn/academic/j_acegi_security_check', data=loging_data.encode(encoding='utf-8'), headers=headers) try: result=opener.open(req)#访问请求的链接 # print(result.read().decode('utf-8')) except urllib2.HTTPError: print("connect failed") try: result=opener.open('http://jwgl.nwsuaf.edu.cn/academic/manager/score/studentOwnScore.do?groupId=&moduleId=2021')#进入教务系统个人成绩信息界面 print(result.read().decode('utf-8')) except urllib2.HTTPError: print("error")
相关文章推荐
- wxPython一个简单文本编辑器
- wxPython的安装与使用
- python程序如何在生产和测试环境自动调用对应的配置文件
- PyQt5的QDataStream类对python类型和PyQt类型的数据进行读写操作简要说明
- Python学习笔记,切片,迭代
- Python 如何操作MYSQL数据库
- 2017年Python技能图谱(价值498元)-熊盼
- Blender Python 自学指导 视频教程
- Python3图片处理头像
- Python3 快速入门(二)
- windows7 下安装python2.7 setuptools pip
- Python中为什么要使用self?
- Python第二天 变量 运算符与表达式 input()与raw_input()区别 字符编码 python转义符 字符串格式化 format函数字符串格式化 帮助
- pandas中的绘图函数
- pandas中的绘图函数
- pandas中的绘图函数
- wxPython+Matplotlib绘制折线图表
- 机器学习实战学习笔记10——Apriori算法
- Google Python 风格规范
- Python3 快速入门(一)