爬虫js逆向:jquery,ajax简单了解

index.html




    
    Title
    
    
    
    


hello {{name}}


id name
加载中...

.py

import json
import time

from flask import Flask, render_template, request

app = Flask(__name__)


@app.route('/')
def func1():
    name = 'fox'
    return render_template('index.html', name=name)


@app.route('/ajax_req_get')
def ajax_req():
    id = request.args.get('id')
    name = request.args.get('name')
    if not all([id, name]):
        return '缺少参数'
    return 'hello fox!!!'


@app.route('/ajax_req_post', methods=['POST'])
def ajax_req2():
    data = request.json
    time.sleep(2)
    print(data)
    lst = [
        {'id': 1, 'name': '鸣人'},
        {'id': 2, 'name': '佐助'},
        {'id': 3, 'name': '小樱'}
    ]
    # json.dumps(lst, ensure_ascii=False)  # 原样输出中文
    data = json.dumps(lst)
    return data


if __name__ == '__main__':
    app.run()

你可能感兴趣的:(爬虫,ajax,jquery)