Flask获取post,get参数,以及 爬虫 requests的get,post参数详解(flask get请求)

网友投稿 493 2022-08-29


Flask获取post,get参数,以及 爬虫 requests的get,post参数详解(flask get请求)

1.Flask-----get

@app.route('/get',methods=["get"])def get(): print(f"request.args{request.args}") return 'GET!'

View Code

2.Flask-----post

@app.route('/post',methods=["post"])def post(): print(f"request.form{request.form}") print(f"request.get_data{request.get_data()}") print(f"request.get_json{request.get_json()}") print(f"request.files{request.files}") return 'POST!'

View Code

3.爬虫之get方法参数详解

import requests,jsonurl_get = "= {"name":"my name is Get"}res = requests.get(url_get,params=pm)print(res.text)'''1.params = 字典request.argsImmutableMultiDict([('name', 'my name is Get')])'''

View Code

4.爬虫之post方法参数详解

import requests,jsonurl_post = "= {"name":"my name is POST_data"}data_json = {"name":"my name is POST_json"}res = requests.post(url_post,data=json.dumps(data_data),json=data_json)print(res.text)"""有data,那么json就不生效1.json=data_jsonrequest.get_data b'{"name": "my name is POST_json"}'request.get_json {'name': 'my name is POST_json'}2.json=json.dumps(data_json)request.get_datab'"{\\"name\\": \\"my name is POST_json\\"}"'request.get_json{"name": "my name is POST_json"}3.data=data_datarequest.form ImmutableMultiDict([('name', 'my name is POST_data')])4.data=json.dumps(data_data)request.get_data b'{"name": "my name is POST_data"}'"""

View Code

5.爬虫之传参文件:

res = requests.post(url, files={"key": open(file_url, "rb")})

View Code

-----------------------------------------------------------------------------------------------------------------------------------------


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Flask(flask sqlalchemy查询)
下一篇:Java圆通物流轨迹推送服务接口文档及流程
相关文章

 发表评论

暂时没有评论,来抢沙发吧~