参考  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. python 学习笔记(十二) 文件和序列化

    python 文件读写和序列化学习.## python文件读写`1 打开并且读取文件` f = open('openfile.txt','r') print(f.read()) f.close() ` ...

  2. Android的静默安装

    原文 Android的静默安装似乎是一个很有趣很诱人的东西,但是,用普通做法,如果手机没有root权限的话,似乎很难实现静默安装,因为Android并不提供显示的Intent调用,一般是通过以下方式安 ...

  3. 从一个集合中过滤另一个集合中存在的项(类似in)

    直接贴代码出来: List<PriceMark> list = PriceMarkDAL.m_PriceMarkDAL.GetList("Erp_ProName='TLC7528 ...

  4. Install Terraform on Windows, Linux and Mac OS

    Step-by-step tutorial of how to download and install Terraform on Windows, Linux and Mac OS. Terrafo ...

  5. [DeeplearningAI笔记]序列模型2.9情感分类

    5.2自然语言处理 觉得有用的话,欢迎一起讨论相互学习~Follow Me 2.9 Sentiment classification 情感分类 情感分类任务简单来说是看一段文本,然后分辨这个人是否喜欢 ...

  6. Jenkins使用教程之管理节点

    通常的情况下在我们的一个项目当中,项目会有多个分支系统,而我们不可能为每个分支系统都配置一个jenkins服务,这样既浪费资源,也增加构建部署的难度,为了解决这个问题jenkins给使用者提供了非常强 ...

  7. spring boot 2.0.3+spring cloud (Finchley)5、路由网关Spring Cloud Zuul

    Zuul作为微服务系统的网关组件,用于构建边界服务,致力于动态路由.过滤.监控.弹性伸缩和安全. 为什么需要Zuul Zuul.Ribbon以及Eureka结合可以实现智能路由和负载均衡的功能:网关将 ...

  8. CS46 C 枚举二分

    给你n*2个数其中n个数是原数减去了X值的数.问你满足条件的X值和原来的n个数.注意X为正整数. X should be positive,没0的 思路很简单,一个数必定会对应一个数,那么枚举一个数和 ...

  9. Centos7系统环境下Solr之Java实战(二)制定中文分析器、配置业务域

    制定中文分析器 1.把IKAnalyzer2012FF_u1.jar添加到solr工程的lib目录下 2.把扩展词典.配置文件放到solr工程的WEB-INF/classes目录下. 配置一个Fiel ...

  10. Redis-1-Redis的安装

    Redis 什么是Redis? redis是一个开源的.使用C语言编写的.支持网络交互的.可基于内存也可持久化的Key-Value数据库. 安装Redis: windows下如何安装? 官方网址:ht ...