python实现的登录与提交表单数据功能示例
Python  /  管理员 发布于 6年前   115
本文实例讲述了python实现的登录与提交表单数据功能。分享给大家供大家参考,具体如下:
# !/usr/bin/env python# -*- coding: utf-8 -*-import urllib2import urllibimport cookielibimport jsonimport httplibimport reimport requestsimport osimport timeimport requests, requests.utils, pickletry: import cookielib # 兼容Python2except: import http.cookiejar as cookielibs=requests.session()print s.headersfrom requests.packages.urllib3.exceptions import InsecureRequestWarningrequests.packages.urllib3.disable_warnings(InsecureRequestWarning)# with open('cook.txt', 'r') as f:# cookies = json.loads(f.read())# print cookies# try:# with open("cookies.txt", "r") as f:# load_cookies = json.loads(f.read())# s.cookies = requests.utils.cookiejar_from_dict(load_cookies)# print s.get('https://fms.lvchengcaifu.com/welcome').content# except:#url = "https://oauth2.lvchengcaifu.com/login"headers={ 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',}r= s.get(url,headers=headers,verify=False)r=r.textprint rprint type(r)r = r.encode('unicode-escape')print type(r)p = re.compile('.*_csrf"\s+value="(.*?)".*')m = p.match(r)token = m.group(1)print tokenheaders={ 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'csrf_token': token}imgurl='https://oauth2.lvchengcaifu.com/Kaptcha.jpg'r = s.get(imgurl)r = r.content# print sprint type(r)print rfilename = 'E:\image.jpg'local = open(filename, 'wb')local.write(r)local.close()print "登录二维码已经下载到本地" + "[" + filename + "]" ##打开图片os.system("start %s" % filename);code = raw_input('输入验证码: ')print codeprint len(code)## <input type="hidden" id="_csrf" name="_csrf" value="6f772fd9-14da-40c4-b317-e8d9a4336203" />login_url='https://oauth2.lvchengcaifu.com/login/form'data = {'username': '1111', 'password': '2222@', '_csrf': token,'validCode':code}response = s.post(login_url, data=data,headers=headers)print response.contentaa=s.cookiesprint '-------------------------------------'print aa
更多关于Python相关内容可查看本站专题:《Python Socket编程技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》
希望本文所述对大家Python程序设计有所帮助。
123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号