python requests库学习
Requests python的request库官方介绍就是让HTTP服务人类,所以从这点我们就可以知道request库是为了让我们更加方便的进行http相关的各种操作 我们学习request有什么用呢? 1)web时代我们需要熟悉掌握web交互原理 2)爬虫 3)服务器编程 4)自动化测试 实验环境准备 首先是环境的准备,首先我们肯定要装requests库 直接使用pip命令即可(注意:本文使用的是py3.6版本) 同时我们需要一个服务器来测试我们的各种操作,我们可以直接使用requests库作者写的一个网站 httpbin.org 来进行我们的各种实验操作 requests例程 我们可以从下面的简单的例程来简单了解下requests import requests #实验web地址 http://httpbin.org url_ip='http://httpbin.org/ip' url_get='http://httpbin.org/get' #直接使用 def requests_simple(): #利用get方法得到一个response response1=requests.get(url_ip) #打印头部headders print('Response Headers:',response1.headers) #打印Body print('Response Body: