参考  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. [转载]DataView详解

    表示用于排序.筛选.搜索.编辑和导航的 DataTable 的可绑定数据的自定义视图. DataView的功能类似于数据库的视图,他是数据源DataTable的封装对象,可以对数据源进行排序.搜索.过 ...

  2. Codeforces 449.C Jzzhu and Apples

    C. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Uoj308【UNR #2】UOJ拯救计划

    分析:比较难分析的一道题,先把式子写出来,ans=∑C(k,i)*f(i),f(i)是选i个颜色的方案数.这个模数有点奇怪,比较小而且是合数,说不定就会有某种规律,如果i >= 3,可以发现C( ...

  4. 题解 P2762 【太空飞行计划问题】

    P2762 太空飞行计划问题 题目描述 W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,-,Em},和进 ...

  5. 使用RVM轻松部署Ruby环境

    Ruby用得不多,但发现有业务需要部署指定的版本和插件.起初找了一些Fedora的src.rpm重新打包,发现依赖问题比较多,最终还是费劲的把el6的包编出来了. 不巧今天又有业务要求el5的包,原本 ...

  6. Codeforces 797 D. Broken BST

    D. Broken BST http://codeforces.com/problemset/problem/797/D time limit per test 1 second memory lim ...

  7. mysql 导出数据导致锁表

    故事原由:今天同事小星做系统优化时问我一个sql问题,为什么查询慢,我看了一眼,发现用到了表A中的datetime类型列进行时间比较,建议他给datetime类型列加上索引. 可这是生产库,表A里面有 ...

  8. 动态加载js和css的jquery plugin

    一个简单的动态加载js和css的jquery代码,用于在生成页面时通过js函数加载一些共通的js和css文件. //how to use the function below: //$.include ...

  9. python学习笔记(十三)之lambda表达式

    lambda表达式: 用法 lambda x : 2 * x + 1 其中:前面是参数,后面是返回值. >>> def ds(x): ... return 2 * x + 1 ... ...

  10. NYOJ 208 Supermarket (模拟+并查集)

    题目链接 描述 A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Pr ...