Python——requests模块
一、安装模块
pip install requests
二、引用
import requests
三、get方法
#GET访问页面
r = requests.get(url)
print(r.text)
#GET传参数
r = requests.get('https://www.douban.com/search',params={'q':'python','cat':'1001'})
print(r.url)
#https://www.douban.com/search?q=python&cat=1001
#传递Header头,需要headers的参数
r = requests.get('https://www.douban.com/', headers={'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit'})
四、post方法
#post方法,传递需要data参数
r = requests.post('https://accounts.douban.com/login', data={'form_email': 'abc@example.com', 'form_password': '123456'})
#传递json参数
params = {'key': 'value'}
r = requests.post(url, json=params)
#上传文件类编码格式
upload_files = {'file': open('report.xls', 'rb')}
r = requests.post(url, files=upload_files)
五、其他参数
1.传递cookies参数
cs = {'token': '12345', 'status': 'working'}
r = requests.get(url, cookies=cs)
Python——requests模块的更多相关文章
- 使用python requests模块搭建http load压测环境
网上开源的压力测试工具超级的多,但是总有一些功能不是很符合自己预期的,于是自己动手搭建了一个简单的http load的压测环境 1.首先从最简单的http环境着手,当你在浏览器上输入了http://w ...
- Python requests模块学习笔记
目录 Requests模块说明 Requests模块安装 Requests模块简单入门 Requests示例 参考文档 1.Requests模块说明 Requests 是使用 Apache2 Li ...
- Python—requests模块详解
1.模块说明 requests是使用Apache2 licensed 许可证的HTTP库. 用python编写. 比urllib2模块更简洁. Request支持HTTP连接保持和连接池,支持使用co ...
- Windows下安装Python requests模块
在使用自己写的或者别人的python小工具时可能会出现类似ImportError: No module named Requests的问题: D:\tool\python\fuzz>Fuzz.p ...
- 使用monkey技术修改python requests模块
例如请求前和请求后各来一条日志,这样就不需要在自己的每个代码都去加日志了. 其实也可以直接记录'urllib3.connectionpool' logger name的日志. 修改了requests ...
- Python requests模块params、data、json的区别
json和dict对比 json的key只能是字符串,python的dict可以是任何可hash对象(hashtable type): json的key可以是有序.重复的:dict的key不可以重复. ...
- Python requests模块
import requests 下面就可以使用神奇的requests模块了! 1.向网页发送数据 >>> payload = {'key1': 'value1', 'key2': [ ...
- python requests模块的两个方法content和text
requests模块下有两个获取内容的方法,很奇怪,都是获取请求后内容的方法,有什么区别呢?? 一.区别 content:返回bytes类型的数据也就是二进制数据 text:返回的就是纯文本(Unic ...
- python requests模块session的使用建议及整个会话中的所有cookie的方法
话不多说,直接上代码 测试代码 服务端 下面是用flask做的一个服务端,用来设置cookie以及打印请求时的请求头 # -*- coding: utf-8 -*- from flask import ...
随机推荐
- js reduce数组转对象
借鉴:https://juejin.im/post/5cfcaa7ae51d45109b01b161#comment这位大佬的处理方法很妙,但是我一眼看过去没有明白,细细琢磨了下,终于明白了 1 co ...
- UI测试框架
1. 从上到下共分成4层: 用例层 组件管理层 元素管理层 公共数据层 2. 用例层: 将每条用例使用参数化, 公共参数存储到"公共数据层", 中间参数通过组件层传递 3. ...
- kubernetes 核心技术-Controller 控制器
一.什么是Controller? Controller是在集群上管理和运行容器的对象,Controller是实际存在的,Pod是抽象的,主要创建管理pod 二.Pod和Controller的关系 Po ...
- 001.IT运维面试问题-Linux基础
Linux基础 简述Linux主流的发行版? Redhat.CentOS.Fedora.SuSE.Debian.Ubuntu.FreeBSD等. 简述Linux启动过程? ⑴开机BIOS自检,加载硬盘 ...
- Spring之 IOC&依赖注入
0x01.Spring 1什么是Spring Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的(解耦). 框架的主要优势之一就是其分层架构,分层架构允许您选择使用哪一个组 ...
- 给定HDFS中某一个目录,输出该目录下的所有文件的读写权限、大小、创建时间、路径等信息,如果该文件是目录,则递归输出该目录下所有文件相关信息。
1 import java.text.SimpleDateFormat; 2 import org.apache.hadoop.fs.*; 3 4 public class E_RecursiveRe ...
- 览器全面禁用三方 Cookie 全栈前端精选 4月16日
览器全面禁用三方 Cookie 全栈前端精选 4月16日
- Beating JSON performance with Protobuf https://auth0.com/blog/beating-json-performance-with-protobuf/
Beating JSON performance with Protobuf https://auth0.com/blog/beating-json-performance-with-protobuf ...
- Optimal asymmetric encryption padding 最优非对称加密填充(OAEP)
SubtleCrypto.decrypt() - Web APIs | MDN https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypt ...
- LOJ10098
USACO 2006 Jan. Gold 为了从F个草场中的一个走到另一个,贝茜和她的同伴们不得不路过一些她们讨厌的可怕的树.奶牛们已经厌倦了被迫走某一条路,所以她们想建一些新路,使每一对草场之间都会 ...