python实现的登录与提交表单数据功能示例
作者:zhaoyangjian724 时间:2021-04-28 21:16:38
本文实例讲述了python实现的登录与提交表单数据功能。分享给大家供大家参考,具体如下:
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import json
import httplib
import re
import requests
import os
import time
import requests, requests.utils, pickle
try:
import cookielib # 兼容Python2
except:
import http.cookiejar as cookielib
s=requests.session()
print s.headers
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.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.text
print r
print 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 token
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',
'csrf_token': token
}
imgurl='https://oauth2.lvchengcaifu.com/Kaptcha.jpg'
r = s.get(imgurl)
r = r.content
# print s
print type(r)
print r
filename = 'E:\image.jpg'
local = open(filename, 'wb')
local.write(r)
local.close()
print "登录二维码已经下载到本地" + "[" + filename + "]"
##打开图片
os.system("start %s" % filename);
code = raw_input('输入验证码: ')
print code
print 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.content
aa=s.cookies
print '-------------------------------------'
print aa
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/zhaoyangjian724/article/details/100065689
标签:python,登录,提交,表单数据
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
django表单实现下拉框的示例讲解
2022-03-24 09:18:25
聊聊golang中多个defer的执行顺序
2023-09-03 09:23:22
轻松接触SQL Server 2000实例的命名规则
2009-01-23 13:44:00
一文带你了解Python中的输入与输出
2023-11-26 12:05:24
![](https://img.aspxhome.com/file/2023/4/91884_0s.png)
已安装tensorflow-gpu,但keras无法使用GPU加速的解决
2021-08-15 12:17:42
![](https://img.aspxhome.com/file/2023/6/81736_0s.jpg)
Python实现TCP协议下的端口映射功能的脚本程序示例
2021-07-26 13:59:01
![](https://img.aspxhome.com/file/2023/2/93712_0s.png)
three.js中文文档学习之创建场景
2023-08-22 21:02:00
ASP(JScript)构建SQL语句“类”
2008-04-30 07:12:00
Golang之defer 延迟调用操作
2023-08-04 18:21:48
![](https://img.aspxhome.com/file/2023/6/95346_0s.jpg)
asp如何分页显示数据库查询结果?
2009-11-22 19:23:00
python实现Zabbix-API监控
2022-04-23 17:41:00
![](https://img.aspxhome.com/file/2023/5/71505_0s.jpg)
通过事务日志解决SQL Server常见四大故障
2009-03-25 16:06:00
python实现监控阿里云账户余额功能
2022-08-19 23:43:32
![](https://img.aspxhome.com/file/2023/9/127759_0s.jpg)
Python利用imshow制作自定义渐变填充柱状图(colorbar)
2023-07-14 00:27:57
![](https://img.aspxhome.com/file/2023/8/109498_0s.png)
用pytorch的nn.Module构造简单全链接层实例
2022-01-04 00:00:17
Django中Aggregation聚合的基本使用方法
2023-09-15 02:38:29
利用Python批量压缩png方法实例(支持过滤个别文件与文件夹)
2021-07-16 11:37:24
JS的IE和FF兼容性问题汇总
2008-03-08 13:01:00
AJAX无刷新验证用户名是否存在
2007-08-10 10:07:00
PyQt5实现下载进度条效果
2022-06-17 10:47:11
![](https://img.aspxhome.com/file/2023/5/115025_0s.png)