maimang00 2020-06-12
注:requests不是python内置的库,需要单独安装,pip3 install requests
功能详解:
基本GET请求:
import requests response = requests.get(‘http://httpbin.org/get‘) print(response.text)
基本POST请求:
post请求需要添加一个data参数,该参数是由字典构造
import requests data= { ‘name‘:‘miu‘, ‘age‘:24 } response = requests.post(‘http://httpbin.org/post‘,data=data) print(response.text)
响应:
import requests response = requests.get("http://www.baidu.com") print(type(response.status_code),response.status_code) print(type(response.headers),response.headers) print(type(response.cookies),response.cookies) print(type(response.url),response.url) print(type(response.history),response.history)