使用python将请求的requests headers参数格式化方法
import json # 使用三引号将浏览器复制出来的requests headers参数赋值给一个变量
headers = """
Host: zhan.qq.com
Proxy-Connection: keep-alive
Content-Length: 799432
Pragma: no-cache
Cache-Control: no-cache
Origin: https://www.colorgg.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryuptjZg9xmsfWzngP
Accept: */*
Referer: https://www.colorgg.com
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Cookie: pgv_pvi=4342937600; RK=xFr4lrf07R; ptcz=a247c6170fb56cb4d5d41bf8461f11097a9be27bc7e7dc8b921254de9b1c924b;
""" # 去除参数头尾的空格并按换行符分割
headers = headers.strip().split('\n') # 使用字典生成式将参数切片重组,并去掉空格,处理带协议头中的://
headers = {x.split(':')[0].strip(): ("".join(x.split(':')[1:])).strip().replace('//', "://") for x in headers} # 使用json模块将字典转化成json格式打印出来
print(json.dumps(headers,indent=1))
使用python将请求的requests headers参数格式化方法的更多相关文章
- python 网络请求类库 requests 使用
python 网络请求类库 requests 使用 requests是 为python封装的强大 REST 操作类库 githubhttps://github.com/kennethreitz/req ...
- java遍历http请求request的所有参数实现方法
方法一: 通过程序遍历http请求的所有参数放到hashmap中,用的时候方便了. 如果参数值有中文,那么需要在程序中添加filter转码,或者在下面程序里,对paramValue转码 Map map ...
- Python利器一之requests
Python利器一之requests 一.教程涉及开发语言.脚本.框架.数据库等内容 Python + requests 通过 pip 安装: pip install requests 通过 easy ...
- 【Python】 requests 各种参数请求的方式
Python使用requests发送post请求 1.我们使用postman进行接口测试的时候,发现POST请求方式的编码有3种,具体的编码方式如下: A:application/x-www-form ...
- python非转基因HTTP请求库--Requests: 让 HTTP 服务人类
快速上手 迫不及待了吗?本页内容为如何入门 Requests 提供了很好的指引.其假设你已经安装了 Requests.如果还没有,去安装一节看看吧. 首先,确认一下: Requests 已安装 Req ...
- Python+Post请求中涉及到多个参数data方法的应用
进行post请求,Python提供了httplib.urllib2,同时也可以引用requests模块的一些方法.前几天做持续集成,运用requests写了一个post请求.代码如下: import ...
- requests.get() 的 headers 参数
官方文档requests.get()方法的定义如下: 源码如下: 看到最后一行return,get方法最后是通过调用requests.request 方法实现的,其实在其它的请求方法如post,put ...
- Python爬虫【二】请求库requests
一.requests的常用请求方式 #各种请求方式:常用的就是requests.get()和requests.post() >>> import requests >>& ...
- Python常见问题 - python3 使用requests发送HTTPS请求报certificate verify failed 错误
当你使用 requests 发送HTTPS请求时 requests.get(url, parmas=parmas, headers=header, cookies=cookie) 出现了以下错误 HT ...
随机推荐
- robot framework 接口post请求需要加headers
说明:当你用RF进行post接口测试时候,那么需要加个headers=Content-Type=application/x-www-form-urlencoded,要不然会请求不成功的.
- mysql 连接数据库时时区报错
1.url: jdbc:mysql://192.168.0.101:3306/testdb?serverTimezone=UTC,在连接字符后面添加时区设置 2.使用navicat或者直接使用mysq ...
- 最大流dinic板子
题目: https://www.luogu.com.cn/problem/P3376 #include <bits/stdc++.h> using namespace std; ; con ...
- 06. Z字型变换
题目: 提交01: class Solution { public String convert(String s, int numRows) { int length = 2*numRows-2; ...
- Java连载78-深入自动拆装箱、Date类和SimpleDateFormat格式化
一.深入自动拆装箱 1.直接举例: public class D78_AutomaticUnpackingAndPacking{ public static void main(String[] ar ...
- js通过cookie对两个没有关系的jsp页面进行传值
//Cookie取值 function readCookie (name) { var cookieValue = ""; var search = name + "=& ...
- Python 中的else
在其他程序语言中,else 似乎只是与 if 关键字有缘分.而与其他的关键字没有联系,不能搭配使用,而在python中,else 除了与 if 匹配外, 还可以与for.while/ try等关键字匹 ...
- pyhton的返回值
a=input() input()函数返回的是字符‘2’ a=bin(2) bin函数返回的是二进制形式的字符串'0b10' type()判断类型 bin()转化成二进制 int(a,2)可以强制把字 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 辅助类:显示关闭按钮
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 视图家族 & 路由组件
目录 视图家族 & 路由组件 视图集与路由组件 基于 GenericAPIView 的十大接口 基于 generics 包下工具视图类的六大基础接口 视图集 路由组件:必须配合视图集使用 自定 ...