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
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()
def __init__(self, merchantid, use_proxy=False): self.net = NetProcess() self.__use_proxy = False if use_proxy: self.set_proxy(merchantid) self.__use_proxy = True
def __init__(self): self.HttpR = NetProcess() self.XICIURL = 'http://www.xici.net.co/nn/' self.KUAI = 'http://www.kuaidaili.com/free/inha/' self.CNPROXY = 'http://cn-proxy.com/' self.ip_list = []