使用Python爬虫库requests发送表单数据和JSON数据
2021-03-11 15:34
标签:headers target files enc app accept use url 需要 更多python教程请到: 菜鸟教程www.piaodoo.com 人人影视www.sfkyty.com 16影视www.591319.com 星辰影院www.591319.com 导入Python爬虫库Requests 一、发送表单数据 要发送表单数据,只需要将一个字典传递给参数data 也可以将一个元组列表传递给参数data,这样可以实现多个value对应一个key的情况(字典的key必须唯一) 二、发送字符串(JSON)数据 将json字符串传递给参数data 将字典传递给参数json 更多关于Python爬虫库requests的使用方法请查看下面的相关链接 使用Python爬虫库requests发送表单数据和JSON数据 标签:headers target files enc app accept use url 需要 原文地址:https://www.cnblogs.com/piaodoo/p/14125580.htmlimport requests
payload = {‘key1‘: ‘value1‘, ‘key2‘: ‘value2‘}
r = requests.post("http://httpbin.org/post", data=payload)
print(r.text)
{"args":{},"data":"","files":{},"form":{"key1":"value1","key2":"value2"},"headers":{"Accept":"*/*","Accept-Encoding":"gzip, deflate","Connection":"close","Content-Length":"23","Content-Type":"application/x-www-form-urlencoded","Host":"httpbin.org","User-Agent":"python-requests/2.14.2"},"json":null,"origin":"110.18.198.88","url":"http://httpbin.org/post"}
payload = ((‘key1‘, ‘value1‘), (‘key1‘, ‘value2‘))
r = requests.post(‘http://httpbin.org/post‘, data=payload)
print(r.text)
{"args":{},"data":"","files":{},"form":{"key1":["value1","value2"]},"headers":{"Accept":"*/*","Accept-Encoding":"gzip, deflate","Connection":"close","Content-Length":"23","Content-Type":"application/x-www-form-urlencoded","Host":"httpbin.org","User-Agent":"python-requests/2.14.2"},"json":null,"origin":"110.18.198.88","url":"http://httpbin.org/post"}
import json
url = ‘https://api.github.com/some/endpoint‘
payload = {‘some‘: ‘data‘}
r = requests.post(url, data=json.dumps(payload))
url = ‘https://api.github.com/some/endpoint‘
payload = {‘some‘: ‘data‘}
r = requests.post(url,json=payload)
上一篇:导入aliyun-oss-spring-boot-starter依赖报错Cannot resolve com.alibaba.cloud:aliyun-oss-spring-boot-starter:
下一篇:JQuery中的选择器
文章标题:使用Python爬虫库requests发送表单数据和JSON数据
文章链接:http://soscw.com/index.php/essay/63268.html