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
5.爬虫之传参文件:
res = requests.post(url, files={"key": open(file_url, "rb")})