# 使用 Requests 发送网络请求
# 1、导入 Requests 模块
import requests
# 2、尝试获取某个网页

# HTTP 请求类型
r = requests.get('https://api.github.com/events')
r = requests.post('http://httpbin.org/post', data = {'key':'value'})
r = requests.put('http://httpbin.org/put', data = {'key':'value'})
r = requests.delete('http://httpbin.org/delete')
r = requests.head('http://httpbin.org/get')
r = requests.options('http://httpbin.org/get')
# 通过打印输出该 URL
r.url

# 服务器相应内容
# 1、读取服务器响应的内容
r.text
# Requests文本编码,能够使用 r.encoding 属性来改变它
r.encoding
# 2、二进制响应内容,以字节的方式访问请求响应体,对于非文本请求
r.content
# 3、JSON 响应内容,内置的 JSON 解码器,助你处理 JSON 数据
r.json()
# 获取来自服务器的原始套接字响应
r.raw

posted on 2019-03-18 18:21  &&||!  阅读(137)  评论(0编辑  收藏  举报