Python模拟登录(带验证码)
2016-02-05 00:00
691 查看
摘要: python模拟登录源码记录
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)
相关文章推荐
- K均值聚类算法Demo
- saltstack python api 调用
- Odd Even Linked List
- 《笨办法学Python》 第33课手记
- python正则表达式
- python 基础
- Python 15.2 POP3 收取邮件
- python中yield语句详解——译自stack overflow
- Python全局变量
- python 基础(一)
- 批量检测文件字符编码集并转换编码的python脚本
- Python学习基础之函数
- python ip地址转换
- python共享文件夹
- python 逆波兰式
- Python基础学习笔记(一)环境安装
- Python脚本
- Python中的时间相关问题
- Python爬虫基础
- Python中常用操作字符串的函数与方法总结