Ejemplo n.º 1
0
def getproxy(args = None):
    a = NetProcess()
    a.Host = 'www.hao123.com'
    errmsg = ''
    myproxy = SProxy()
    ip_list = myproxy.renew_proxy()
    newitems = 0
    for item in ip_list:
        try:
            ishave = Proxy.objects.filter(ip = str(item))
            if ishave.count() > 0:
                continue
            a.Proxy = item
            res = a.GetResFromRequest('GET', "http://www.hao123.com/", 'utf-8', use_proxy=True)
            if isinstance(res, str):
                newitems += 1
                newproxy = Proxy()
                newproxy.ip = item
                newproxy.is_online = True
                newproxy.is_used = False
                newproxy.req_times = 0
                newproxy.get_time = datetime.datetime.now()
                newproxy.save()
        except Exception, e:
            except_handle(e)
            errmsg = str(e)
            continue
Ejemplo n.º 2
0
def checkproxy(args = None):
    a = NetProcess()
    useless = 0
    off = Proxy.objects.filter(is_online = False).delete()
    oters = Proxy.objects.all()
    print oters.count()
    for item in oters:
        a.Proxy = item.ip
        res = a.GetResFromRequest('GET', "http://napos.ele.me/login", 'utf-8', use_proxy=True)
        if not isinstance(res, str):
            print 'del ' + item.ip
            item.delete()
            useless += 1
        else:
            # print res
            print item.ip + ' connect success'
    content = '代理检验完成,删除无效代理' + str(useless) + '个'
    print content
    newlog = CronLog()
    newlog.ltype = 2
    newlog.content = content
    newlog.status = True
    newlog.save()