request学习笔记

xiaoxiao2021-02-28  43

上requests 官方文档去看全面 一、 1.发送请求 r = requests.get(url) r = requests.post(url) 2.其他请求: .put()   .delete()   .head()   .options() 二、传递url参数 import requests url = 'http://v.juhe.cn/wz/citys' params = {} //建一个字典 params['province'] = 'BJ' params['key'] = '6052b7a960c5c31a8ec04203ebac740e'    r = requests.get(url, params=params) print(r.url) # http://v.juhe.cn/wz/citys?province=BJ&key=6052b7a960c5c31a8ec04203ebac740e print(r) 三、响应内容 1.文本 2.二进制 3.json 四、提交文件 post请求 def post_multipart_encoded():     url='http://httpbin.org/post'     files = {'file':open('test.jpg','rb')}     r=requests.post(url,files=files)     print(r.text)
转载请注明原文地址: https://www.6miu.com/read-2631236.html

最新回复(0)