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

作者:mrr 时间:2022-09-04 04:41:37 

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


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,登录,验证码
0
投稿

猜你喜欢

  • es6中some和every方法使用简单示例

    2024-06-05 09:10:39
  • python中三种输出格式总结(%,format,f-string)

    2022-06-11 16:34:40
  • python 百度aip实现文字识别的实现示例

    2023-12-15 19:53:47
  • mysql 5.7.13 安装配置方法图文教程(linux)

    2024-01-27 20:46:37
  • 利用python实现查看溧阳的摄影圈

    2021-09-05 21:33:16
  • PHP 使用redis简单示例分享

    2024-05-05 09:18:16
  • 一文教你用Python中progress库实现进度条

    2023-09-14 10:28:31
  • Python Pygame实现俄罗斯方块

    2023-03-17 07:18:03
  • CentOS中使用virtualenv搭建python3环境

    2022-08-30 07:28:43
  • MySQL操作数据库和表的常用命令新手教程

    2024-01-23 23:18:36
  • js实现网页加载loading的显示

    2007-11-06 12:11:00
  • mssql存储过程表名和字段名为变量的实现方法

    2011-12-01 07:59:13
  • ASP.NET MVC实现区域或城市选择

    2023-07-13 17:50:00
  • Python类的动态绑定实现原理

    2022-05-02 00:52:03
  • asp函数转换xml中的实体字符[转义符]

    2008-10-16 17:07:00
  • 查看django执行的sql语句及消耗时间的两种方法

    2021-03-28 13:33:48
  • Python 中 Pandas 文件操作和读取 CSV 参数详解

    2021-04-13 01:14:25
  • 在生成的静态页面中统计点击次数

    2009-11-19 13:20:00
  • 如何查询占CPU高的oracle进程

    2024-01-27 13:16:54
  • js 兼容多浏览器的回车和鼠标焦点事件代码(IE6/7/8,firefox,chrome)

    2024-04-23 09:24:07
  • asp之家 网络编程 m.aspxhome.com