python 模拟登录 中国科大 教务处系统
2014-12-08 08:31
274 查看
python 模拟登录中国科大教务处系统
使用python3.4+requests虽说学校的教务系统页面做的确实不怎么样,但是登录也还算简单,在这里点击学生入口,向服务器post了一个‘s’
然后在登录页面向服务器post了用户名和密码,以及验证码,验证码的获取相对比较简单,
这是验证码的链接。获得验证码后下载下来用图片查看器查看就可以了。
代码如下:
import requests import codecs from PIL import Image def htmlwrite(text, filename='index.html'): htmlfile = codecs.open(filename, 'w', 'utf-8') # mis 页面使用了gbk编码,使用utf-8保存会导致浏览器中打开页面乱码 htmlfile.write(text) htmlfile.close() # 新建保持会话 s = requests.session() url = 'http://mis.teach.ustc.edu.cn' r = s.get(url) # 初次使用,记录cookie等信息 # 从教务处网页跳转到学生登录页面 postdataUserType = {'userbz': 's', } UrlToPostType = 'http://mis.teach.ustc.edu.cn/userinit.do' r = s.post(UrlToPostType, data=postdataUserType) # 获取验证码链接 string = r.text begin_number = string.find("randomImage.do?date='") # todo 使用html解析器进行解析 check_code_url = url + '/' + string[begin_number:begin_number + 35] # print(check_code_url) # 获取验证码 local_filename = 'test.jpg' r = s.get(check_code_url, stream=True) with open(local_filename, 'wb+') as f: for chunk in r.iter_content(chunk_size=1024): if chunk: f.write(chunk) f.flush() f.close() Ima = Image.open('test.jpg') Ima.show() # 用户登录信息输入 userCode = input('请输入用户名') passWord = input('请输入密码') check_code = input('请输入验证码: ') # 正式登陆 postdataUserInfo = { 'check': check_code, 'hidjym': '', 'userCode': userCode, 'passWord': passWord, 'userbz': 's' } r = s.post('http://mis.teach.ustc.edu.cn/login.do', data=postdataUserInfo)
相关文章推荐
- python模拟登录URP教务系统评教
- 用python写的模拟系统登录三次验证简单程序
- python模拟登录URP教务系统评教
- Python项目模拟登录学校正方教务系统抓取课程表。
- Python模拟登录东北大学教务处
- python练习小工具之模拟登录系统
- python爬虫实战之模拟正方教务系统登录查询成绩
- Python_模拟登录(爬取教务系统信息并制作查询界面)
- python爬虫获取强智科技教务系统学科成绩(模拟登录+成绩获取)
- python---模拟用户正常登录系统,破解用户名与登录密码
- Python练习项目——模拟ATM机登录系统
- Python爬虫实战——模拟登录教务系统
- 利用python3.4爬取学校教务系统,并封装成api供app调用(二)之不带验证码模拟登录
- python爬虫实战之模拟正方教务系统登录查询成绩
- 用Python模拟登录正方教务系统并抓取初始网页的一些个人笔记
- python模拟登录的实现
- 如何利用python模拟登录(附源码)
- Python网页抓取、模拟登录
- C# winform 窗体接收命令行参数自动登录进行系统,模拟600个WCF客户端的并发压力测试
- python模拟登录(一)