python使用 request 发送表单数据操作示例
作者:zhaoyangjian724 发布时间:2022-08-06 07:31:07
标签:python,request,发送表单数据
本文实例讲述了python使用 request 发送表单数据操作。分享给大家供大家参考,具体如下:
# !/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': '11111', 'password': '2222@', '_csrf': token,'validCode':code}
response = s.post(login_url, data=data,headers=headers)
print response.content
aa=s.cookies
print '-------------------------------------'
print aa
# print s.get('https://oauth2.lvchengcaifu.com/oauth/authorize?scope=info_read&response_type=code&redirect_uri=https%3A%2F%2Ffms.lvchengcaifu.com%2Foauthclient%2FoauthCallback&client_id=client-fms').content
print s.get('https://fms.lvchengcaifu.com/welcome', allow_redirects=False).content
cookies = requests.utils.dict_from_cookiejar(s.cookies)
with open("cookies.txt",'w') as fp:
json.dump(cookies, fp)
print(cookies)
url2='https://fms.lvchengcaifu.com/welcome'
r= s.get(url2,headers=headers,verify=False)
r= r.text
##<input type="hidden" id="csrf_token" name="csrf_token" value="a9c21ac8-8412-4853-ae50-98689b2822ac"/>
r = r.encode('unicode-escape')
print type(r)
p = re.compile('.*csrf_token"\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,
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With':'XMLHttpRequest',
'Accept':'application/json, text/javascript, */*; q=0.01'
}
url3='https://fms.lvchengcaifu.com/productOrder/queryComPdAmountOrderInfoList'
data = {'queryParam': {},'page':1,'rows':10}
response = s.post(url3, data=data,headers=headers)
print response.content
print response.status_code
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/zhaoyangjian724/article/details/100064257


猜你喜欢
- 最简单的办法就是直接在php程序代码中加入下面代码:error_reporting(E_ALL^E_NOTICE^E_WARNING);可以
- 前端版本更新检查,实现页面自动刷新使用vite对项目进行打包,对 js 和 css 文件使用了 chunkhash 进行了文件缓存控制,但是
- join的写法如果用left join 左边的表一定是驱动表吗?两个表的join包含多个条件的等值匹配,都要写道on还是只把一个写到on,其
- python如何修改索引和行列修改索引修改索引之前是自动生成的索引:使用set_index('以xx字段为索引',inpla
- 可以使用虚拟屏幕的方式,在虚拟屏幕上运行浏览器并进行截图操作,这样就不会影响当前屏幕的展示。具体实现可以使用Xvfb和pyvirtualdi
- 最近要做一个网站需要用到天气预报,本来是想找到API,自己写一个自己的天气预报小程序的,没有成功,只好去找现成的代码调用。经过测
- 从一头雾水到模模糊糊,不明原理,暂时记录一下1.安装Qtcratersudo pacman -S qtcreater2.打开Qtcrater
- 需求开发过程中开发者经常面对的一个需求就是:一个项目可能会在不同的环境下运行,本地开发环境、测试环境、灰度环境、生产环境。每个环境的参数和配
- 这篇文章利用的是matplotlib.pyplot.plot的工具来绘制折线图,这里先给出一个段代码和结果图:# -*- coding: U
- 我们打包APP需要用到HBuilder,所以先讲解如何安装使用HBuilder的下载与安装HBuilder的官网下载地址:https://w
- 最近开始学习Qt,结合之前学习过的caffe一起搭建了一个人脸识别登录系统的程序,新手可能有理解不到位的情况,还请大家多多指教。我的想法是用
- 需求:两个文件,一个文件为统计报表,里面含有手机号,另一个文件为手机号段归属地,含有手机号码前七位对应的地区。需要对统计报表进行处理,将手机
- 一、Python介绍从我开始学习Python时我就决定维护一个经常使用的“窍门”列表。不论何时当我看到一段让我觉得“酷,这样也行!”的代码时
- 楔子随着自媒体时代,现在对视频的处理变得越来越常见。我们可以使用Adobe的一些专业工具,但是效率不高;如果只是对视频进行一些简单的处理的话
- MaxDB是MySQL AB公司通过SAP认证的数据库。MaxDB数据库服务器补充了MySQL AB产品系列。某些MaxDB特性在MySQL
- 什么是JSON Web Token?JSON Web Token(JWT)是一个开放标准(RFC 7519),它定义了一种紧凑且自包含的方式
- 这是一篇关于使用JScript RuntimeObject(MSDN)调试的文章。虽然这些例子中的大多数在其他浏览器中不能运行,但在IE 5
- Python numpy和scipy中没有直接插0的函数和方法,这里使用numpy.insert来实现。1,numpy.inser
- 我最新最全的文章都在 南瓜慢说 www.pkslow.com ,欢迎大家来喝茶!1 数据库审计数据库审计是指当数据库有记录变更时,可以记录数
- build.js中的代码会去调用UglifyJS的接口函数以执行压缩任务。 1,去github下载最新的UglifyJS。两种方式下载,如果