码迷,mamicode.com
首页 > 其他好文 > 详细

Flask获取post,get参数,以及 爬虫 requests的get,post参数详解

时间:2021-07-06 16:28:26      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:div   pre   http   none   hid   imm   方法参数   imp   closed   

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,json
url_get = "http://127.0.0.1:5000/get"
pm = {"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,json
url_post = "http://127.0.0.1:5000/post"
data_data = {"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_json
request.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_data
request.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

 

Flask获取post,get参数,以及 爬虫 requests的get,post参数详解

标签:div   pre   http   none   hid   imm   方法参数   imp   closed   

原文地址:https://www.cnblogs.com/3-wusen/p/14976099.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!