index.py 856 字节
Newer Older
梦想橡皮擦's avatar
梦想橡皮擦 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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:
梦想橡皮擦's avatar
梦想橡皮擦 已提交
15
        return "错误请求", 403
梦想橡皮擦's avatar
梦想橡皮擦 已提交
16 17 18 19 20 21 22 23 24 25


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


@antispider.route('/error403')
def error403():
    return "缺少关键参数", 403
梦想橡皮擦's avatar
梦想橡皮擦 已提交
26 27 28 29 30 31 32 33 34


@antispider.route('/cookie_demo')
def cookie_demo():
    if 'story' in request.cookies:
        # 如果存在 'story' cookie,则执行相应操作
        return render_template("antispider/cookie_demo.html")
    else:
        return "没有权限", 403