参考  http://docs.python-requests.org/zh_CN/latest/user/quickstart.html

1.传递url参数

>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.get("http://httpbin.org/get", params=payload)
>>> print(r.url)
http://httpbin.org/get?key2=value2&key1=value1

还可以传递值为列表

>>> payload = {'key1': 'value1', 'key2': ['value2', 'value3']}
>>> r = requests.get('http://httpbin.org/get', params=payload)
>>> print(r.url)
http://httpbin.org/get?key1=value1&key2=value2&key2=value3

2.响应内容

可以取服务器响应的内容,

>>> import requests
>>> r = requests.get('https://github.com/timeline.json')
>>> r.text
u'{"message":"Hello there, wayfaring stranger. If you\u2019re reading
this then you probably didn\u2019t see our blog post a couple of years
back announcing that this API would go away: http://git.io/17AROg Fear
not, you should be able to get what you need from the shiny new Events
API instead.","documentation_url":"https://developer.github.com/v3/act
ivity/events/#list-public-events"}'
>>> r.encoding  
'utf-8'
>>> r.encoding = 'ISO-8859-1' #改变编码方式
r.json() #JSON 响应内容
{u'documentation_url': u'https://developer.github.com/v3/activity/events
/#list-public-events', u'message': u'Hello there, wayfaring stranger.
If you\u2019re reading this then you probably didn\u2019t see our blog
post a couple of years back announcing that this API would go away: http
://git.io/17AROg Fear not, you should be able to get what you need from
the shiny new Events API instead.'}

3. 定制请求头

>>> url = 'https://api.github.com/some/endpoint'
>>> headers = {'user-agent': 'my-app/0.0.1'}
>>> r = requests.get(url, headers=headers)

python requests库的用法的更多相关文章

  1. (转)Python爬虫利器一之Requests库的用法

    官方文档 以下内容大多来自于官方文档,本文进行了一些修改和总结.要了解更多可以参考 官方文档 安装 利用 pip 安装 $ pip install requests 或者利用 easy_install ...

  2. Python爬虫利器一之Requests库的用法

    前言 之前我们用了 urllib 库,这个作为入门的工具还是不错的,对了解一些爬虫的基本理念,掌握爬虫爬取的流程有所帮助.入门之后,我们就需要学习一些更加高级的内容和工具来方便我们的爬取.那么这一节来 ...

  3. Python:requests库、BeautifulSoup4库的基本使用(实现简单的网络爬虫)

    Python:requests库.BeautifulSoup4库的基本使用(实现简单的网络爬虫) 一.requests库的基本使用 requests是python语言编写的简单易用的HTTP库,使用起 ...

  4. 大概看了一天python request源码。写下python requests库发送 get,post请求大概过程。

    python requests库发送请求时,比如get请求,大概过程. 一.发起get请求过程:调用requests.get(url,**kwargs)-->request('get', url ...

  5. python requests库学习笔记(上)

    尊重博客园原创精神,请勿转载! requests库官方使用手册地址:http://www.python-requests.org/en/master/:中文使用手册地址:http://cn.pytho ...

  6. Python——Requests库的开发者接口

    本文介绍 Python Requests 库的开发者接口,主要内容包括: 目录 一.主要接口 1. requests.request() 2. requests.head().get().post() ...

  7. 使用python requests库写接口自动化测试--记录学习过程中遇到的坑(1)

    一直听说python requests库对于接口自动化测试特别合适,但由于自身代码基础薄弱,一直没有实践: 这次赶上公司项目需要,同事小伙伴们一起学习写接口自动化脚本,听起来特别给力,赶紧实践一把: ...

  8. Python requests库的使用(一)

    requests库官方使用手册地址:http://www.python-requests.org/en/master/:中文使用手册地址:http://cn.python-requests.org/z ...

  9. python爬虫---requests库的用法

    requests是python实现的简单易用的HTTP库,使用起来比urllib简洁很多 因为是第三方库,所以使用前需要cmd安装 pip install requests 安装完成后import一下 ...

随机推荐

  1. Web前端之HTML详解20180327

    一.html概述 html就是超文本标记语言的简写,是最基础的网页语言.html通过标签来定义语言,代码都是由标签所组成. 1.html代码从<html>开始</html>结束 ...

  2. win7系统用笔记本共享wifi热点 让手机免费上网

    之前一直在用这个方法把自己的笔记本变成一个wifi热点,让手机也可以直接连wifi上网,节省网费和路由器购买费. 其实就是开启了windows 7的隐藏功能:虚拟WiFi和SoftAP(即虚拟无线AP ...

  3. 认识Java标识符

    标识符定义 认识Java标识符 在编程语言中,标识符就是程序员自己规定的具有特定含义的词,比如类名称,属性名称,变量名等. 问:标识符是神马? 答:标识符就是用于给 Java 程序中变量.类.方法等命 ...

  4. vue添加属性绑定

    html <div id="app-2"> <span v-bind:title="message"> 鼠标悬停几秒钟查看此处动态绑定的 ...

  5. 2.UiSelector API 详细介绍

    一.UiSelector类介绍 //通过各种属性与节点关系定位组件 简单实例: public void testDemo2() throws UiObjectNotFoundException{ Ui ...

  6. array_diff使用注意

    $lost_ids = array_diff($all_ids,$old_ids); //array_diff,$old_ids不可以为null否则返回为null;array_diff起不到效果~~~

  7. tf.transpose函数解析

    tf.transpose函数解析 觉得有用的话,欢迎一起讨论相互学习~Follow Me tf.transpose(a, perm = None, name = 'transpose') 解释 将a进 ...

  8. git分支管理图

  9. 贪心法:K叉哈夫曼树

    NOI2015荷马史诗 一部<荷马史诗>中有 n 种不同的单词,从 1 到 n 进行编号.其中第 i 种单词出现的总次数为 wi.Allison 想要用 k 进制串 si 来替换第 i 种 ...

  10. MySQL异常总结

    1.Packets larger than max_allowed_packet are not allowed MySQL的一个系统参数:max_allowed_packet,其默认值为104857 ...