예제 #1
0
 def retry(self, url, retries, func, code=None):
     responset = self.startRequest(url=url, retries=retries)
     responset = responset.content.decode("utf8", "ignore")
     responset = json.loads(responset)
     webcode = jsonpath.jsonpath(responset, "$..code")[0]
     self.Logger.info([url, "msg %d" % webcode])
     if webcode < 0 and retries < 3:
         if webcode == -403:
             print(webcode, "Need login. Wait 5 sec")
             time.sleep(5)
             Ey.RoboEasyLogin(self.key)
             print("Retry Login...%d " % retries)
             time.sleep(5)
             self.cookie = Ey.getCookie(self.key)
             func(retries=retries + 1, code=code)
         else:
             p = random.randint(5, 15)
             self.Logger.error(
                 ("ErrorCode %d :Sleep %d sec ..." % (webcode, p)))
             time.sleep(p)
             func(retries=retries + 1, code=code)
     if retries == 3 and webcode < 0:
         raise ValueError("HTTPERROR OVER MAX RETRY TIME")
     print("SuccessCode %d " % webcode)
     return responset
예제 #2
0
    def __init__(self, hkey="Robo"):

        name = "RoboSpider"
        self.start_urls = 'https://gw.datayes.com/rrp_adventure/web/supervisor/macro/level/0'
        self.urlContainer = [
            'https://gw.datayes.com/rrp_adventure/web/supervisor/macro/%s',
            'https://gw.datayes.com/rrp_adventure/web/dataCenter/indic/%s?compare=false'
        ]
        self.key = hkey
        self.cookie = Ey.getCookie(self.key)
        self.Logger = logAsisst.imLog(sys.argv[1])()