Python模拟登录验证码(代码简单)


Posted in Python onFebruary 06, 2016

废话不多说了,直接给大家贴代码了。

import urllib
import urllib2
import cookielib
def getImg(picurl):
'''
request for random_code picture and cookie 
'''
pic = opener.open(picurl).read()
with open('./verifyImg.jpg','wb') as emptyPic:
emptyPic.write(pic)
def verifyImg(picpath):
'''
TODO
'''
pass
def login(coo):
loginUrl = 'http://jwxt.wust.edu.cn/whkjdx/Logon.do?method=logon'
data = {'USERNAME':'*****', 'PASSWORD':'*****', 'RANDOMCODE':coo}
#encode the postData
postData = urllib.urlencode(data)

user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
header = {'User-Agent':user_agent,'Referer':'http://jwxt.wust.edu.cn/whkjdx/framework/main.jsp'}
#generate a Request with url,postData headers and cookie
request = urllib2.Request(loginUrl, postData, headers = header)
#post data
content = opener.open(request)
#get html file
mainUrl = 'http://jwxt.wust.edu.cn/whkjdx/framework/main.jsp'
mainContent = opener.open(mainUrl).read()
print mainContent 
if __name__ == '__main__':
cookie = cookielib.CookieJar()
handler = urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(handler)
picurl = 'http://jwxt.wust.edu.cn/whkjdx/verifycode.servlet'
getImg(picurl)
#verifyImg(picpath) 
randomCode = raw_input('Plz input teh randomcode:')
login(randomCode)

以上代码大家看起来很容易吧,有不明白的地方欢迎留言,我会在第一时间和大家取得联系的。在此三水点靠木小编祝大家新年快乐。

Python 相关文章推荐
在Python的Django框架中创建语言文件
Jul 27 Python
使用实现pandas读取csv文件指定的前几行
Apr 20 Python
使用Python AIML搭建聊天机器人的方法示例
Jul 09 Python
Python实现矩阵相乘的三种方法小结
Jul 26 Python
Python模拟浏览器上传文件脚本的方法(Multipart/form-data格式)
Oct 22 Python
在Python中给Nan值更改为0的方法
Oct 30 Python
Python中正则表达式的用法总结
Feb 22 Python
Python-接口开发入门解析
Aug 01 Python
如何爬取通过ajax加载数据的网站
Aug 15 Python
Tensorflow Summary用法学习笔记
Jan 10 Python
Scrapy基于scrapy_redis实现分布式爬虫部署的示例
Sep 29 Python
Django migrate报错的解决方案
May 20 Python
Python上传package到Pypi(代码简单)
Feb 06 #Python
深入讲解Java编程中类的生命周期
Feb 05 #Python
python&MongoDB爬取图书馆借阅记录
Feb 05 #Python
Python中常用操作字符串的函数与方法总结
Feb 04 #Python
Python中的字符串类型基本知识学习教程
Feb 04 #Python
Python的math模块中的常用数学函数整理
Feb 04 #Python
详解Python编程中基本的数学计算使用
Feb 04 #Python
You might like
高亮度显示php源代码
2006/10/09 PHP
PHP远程连接MYSQL数据库非常慢的解决方法
2008/07/05 PHP
PHP has encountered an Access Violation 错误的解决方法
2010/01/17 PHP
学习php设计模式 php实现命令模式(command)
2015/12/08 PHP
PHP实现微信提现功能(微信商城)
2019/11/21 PHP
Js的MessageBox
2006/12/03 Javascript
javascript 利用Image对象实现的埋点(某处的点击数)统计
2012/12/28 Javascript
jquery ajaxSubmit 异步提交的简单实现
2014/02/28 Javascript
javascript使用call调用微信API
2014/12/15 Javascript
jquery获取url参数及url加参数的方法
2015/10/26 Javascript
js弹出框、对话框、提示框、弹窗实现方法总结(推荐)
2016/05/31 Javascript
微信小程序中单位rpx和rem的使用
2016/12/06 Javascript
JS实现去除数组中重复json的方法示例
2017/12/21 Javascript
Vue+SpringBoot开发V部落博客管理平台
2017/12/27 Javascript
angular1.x ui-route传参的三种写法小结
2018/08/31 Javascript
详解小程序BackgroundAudioManager踩坑之旅
2019/12/08 Javascript
[01:03:41]完美世界DOTA2联赛PWL S3 DLG vs Phoenix 第一场 12.17
2020/12/19 DOTA
Python修改MP3文件的方法
2015/06/15 Python
Python for Informatics 第11章 正则表达式(一)
2016/04/21 Python
pandas数据处理基础之筛选指定行或者指定列的数据
2018/05/03 Python
Pipenv一键搭建python虚拟环境的方法
2018/05/22 Python
pandas DataFrame 删除重复的行的实现方法
2019/01/29 Python
Python中的 is 和 == 以及字符串驻留机制详解
2019/06/28 Python
使用OpenCV实现仿射变换—平移功能
2019/08/29 Python
python实现WebSocket服务端过程解析
2019/10/18 Python
django 解决扩展自带User表遇到的问题
2020/05/14 Python
python反爬虫方法的优缺点分析
2020/11/25 Python
加拿大服装和鞋类零售商:Mark’s
2021/01/04 全球购物
二手书店创业计划书
2014/01/16 职场文书
项目采购员岗位职责
2014/04/15 职场文书
教师党员批评与自我批评发言稿
2014/10/15 职场文书
2015年全国爱耳日活动总结
2015/02/27 职场文书
Python通过m3u8文件下载合并ts视频的操作
2021/04/16 Python
Vue.js 带下拉选项的输入框(Textbox with Dropdown)组件
2021/04/17 Vue.js
React + Threejs + Swiper 实现全景图效果的完整代码
2021/06/28 Javascript
Spring Bean是如何初始化的详解
2022/03/22 Java/Android