index.py 596 字节
Newer Older
梦想橡皮擦's avatar
梦想橡皮擦 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
from flask import Blueprint, jsonify, request, redirect, url_for
from flask import render_template

antispider = Blueprint('antispider', __name__, url_prefix='/as')


@antispider.before_request
def before_request():
    user_agent = request.headers.get("User-Agent")
    print(user_agent)
    if "Mozilla" in user_agent:
        # 允许请求通过
        return None
    else:
        return "错误请求",403


@antispider.route('/show')
def index():
    return render_template("antispider/ua_show.html")


@antispider.route('/error403')
def error403():
    return "缺少关键参数", 403