Python语言之requests库
发送请求、传递URL参数、定制headers、接受数据,处理数据等
在Java中用httpclient jar包,在Python中用requests库,即使没有事先下载,在Pycharm开发工具中,出现提示时刻,同意安装即可
1) 发送请求
url='http://baidu.com'
requests.post(url)
requests.put(url)
requests.delete(url)
requests.head(url)
requests.options(url)
GET: 请求指定的页面信息,并返回实体主体。
HEAD: 只请求页面的首部。
POST: 请求服务器接受所指定的文档作为对所标识的URI的新的从属实体。
PUT: 从客户端向服务器传送的数据取代指定的文档的内容。
DELETE: 请求服务器删除指定的页面。
get 和 post比较常见 GET请求将提交的数据放置在HTTP请求协议头中
POST提交的数据则放在实体数据中
2) 定制参数
import requests
response = requests.get("http://localhost:8083/showuser?name=germey&age=22")
response = requests.get("http://localhost:8083/showuser?name=germey&age=22") response = requests.get("http://localhost:8083/showuser?name=germey&age=22")
data={
'name': 'germey',
'age': 22
}
response = requests.get("http://localhost:8083/showuser,param=data}
data2= (
('endDate', '2019-12-12'),
('pageIndex', 0),
('pageSize', 50),
('startDate', '2010-01-01')
) data3= {
"endDate": "2019-12-12",
"pageIndex": 0,
"pageSize": 50,
"startDate": "2010-01-01"
} response2=requests.post(url=url2,headers=headers2,data=json.dumps(data2))
response2=requests.post(url=url2,headers=headers2,data=json.dumps(data3))
print(response2.json())
3)定制header
url2='http://localhost:8094/common-api/v1/point/detail?social=AcxiomChina&user=VP巴黎恋人'
headers2={'token':'MTU1Mjg4NTQxOEFDWElPTS1XRUNIQVQ=','Content-Type':'application/json;charset=UTF-8'}
4)response的处理
response.json() 如果是json格式的返回,转化为json格式
response.cookies
response.status_code
response.url
response.text
response.content
http://cn.python-requests.org/zh_CN/latest/
Python语言之requests库的更多相关文章
- python下载安装requests库
一.python下载安装requests库 1.到git下载源码zip源码https://github.com/requests/requests 2.解压到python目录下: 3.“win+R”进 ...
- 【python接口自动化-requests库】【一】requests库安装
1.概念 requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满 ...
- Python爬虫之requests库介绍(一)
一:Requests: 让 HTTP 服务人类 虽然Python的标准库中 urllib2 模块已经包含了平常我们使用的大多数功能,但是它的 API 使用起来让人感觉不太好,而 Requests 自称 ...
- python爬虫之requests库
在python爬虫中,要想获取url的原网页,就要用到众所周知的强大好用的requests库,在2018年python文档年度总结中,requests库使用率排行第一,接下来就开始简单的使用reque ...
- python 3 关于requests库的 text / content /json
最近在爬SDFDA的数据,刚开始用urllib.request 库,一直连不到数据 : 后来通过CHROME浏览器的F12,发现该 网站用的是JSON格式{}'Content-Type': 'appl ...
- python pip安装requests库总提示:Fatal error in launcher...''
1.python pip安装提示:Fatal error in launcher...'' 我查看了网上都说是电脑同时安装了python2 和python3时候才会有这个错误,但实际上我电脑只安 ...
- Python爬虫:requests 库详解,cookie操作与实战
原文 第三方库 requests是基于urllib编写的.比urllib库强大,非常适合爬虫的编写. 安装: pip install requests 简单的爬百度首页的例子: response.te ...
- Python爬虫之requests库的使用
requests库 虽然Python的标准库中 urllib模块已经包含了平常我们使用的大多数功能,但是它的 API 使用起来让人感觉不太好,而 Requests宣传是 "HTTP for ...
- 【python接口自动化-requests库】【三】优化重构requests方法
一.重构post请求方法 上一张讲了如何使用requests库发送post请求,但是有时候,我们写脚本,不可能这么简单,代码完全不可复用,重复工作,那我们是不是可以想象,把我们的get,post请求, ...
随机推荐
- python web开发——django学习(二)第一个django网站运行成功
1.写message_form.html <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- [LeetCode] 66. Plus One 加一
Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The ...
- Anaconda无法更新
在安装完Anaconda,更新包时 C:\Users\Administrator>conda upgrade --all WARNING: The conda.compat module is ...
- Xshell设置运行自动化脚本
使用Xshell工具连接操作Linux系统,并编写运行自动化脚本示例: 这里介绍一种自动化下载日志文件的例子,下面先贴上编写的脚本,这里脚本命名为cyp-assout-log.js 如下: /* xs ...
- layoutSubviews在什么情况下调用
可以使用layoutSubviews修改UI: 1.init初始化不会触发layoutSubviews 但是是用initWithFrame 进行初始化时,当rect的值不为CGRectZero时,也会 ...
- svn服务安装教程
https://www.cnblogs.com/yankyblogs/p/7282752.html
- Vue(六)插槽(2.6.0+)
插槽在vue2.6.0开始有了新的更新 具名插槽(数据来自父组件) 子组件(定义插槽)这里版本前后没什么变化 <template> <div> <header> & ...
- Ant Design Vue select下拉列表设置默认值
在项目中需要为Ant Design Vue 的 select 组件设置一个默认值,如下图所示的状态下拉选择框,默认选择全部 代码如下: <a-select v-model="query ...
- Spring AOP 创建Advice 基于Annotation
public interface IHello { public void sayHello(String str); } public class Hello implements IHello { ...
- .Net 取树形结构的数据
最近遇到了无限层级数据要读取的问题,所有就写了个. 根据当前所有父级,查询出子级内容 private void GetTypeOfWorkforTree(out List<TypeOfWorkD ...