zoukankan      html  css  js  c++  java
  • 爬虫 (反爬)

    再爬虫过程中,我们爬着爬着,他就会阻止你浏览页面,说明对方已经在页面上设置了反爬。

    而我,今天用 装饰器的方法,也制定了一个反爬!

    下面 ,则是详解代码

    def limit(seconds=1):
    # 定义内部方法
    def rate_limit(func):
    def func_limit(request):
    # 设置当前时间
    now =time.time()
    # 获取首次来访时间
    request_time = request.session.get('req_time',0)
    # 做减法
    in_time = int(now) - request_time

    # 判断访问者在一秒内来了不止一次
    if in_time < seconds:
    # 抛出异常
    return HttpResponse('你是爬虫,不要来了',status=403)
    else:
    # 来的时间点存储
    request.session['req_time']=time.time()
    # 让访问者继续访问
    ret = func(request)
    return ret
    return func_limit
    return rate_limit
  • 相关阅读:
    mysql优化
    c语言学习的第10天
    学习c语言的第9天
    学习c的第8天
    学习c的第7天
    学习c的第6天2
    c语言学习的第6天
    sed命令实战
    grep命令实战
    c语言学习的第五天
  • 原文地址:https://www.cnblogs.com/lyp0626/p/10295266.html
Copyright © 2011-2022 走看看