Python: maximum recursion depth exceeded while calling a Python object

后端 未结 4 1837
半阙折子戏
半阙折子戏 2020-12-05 02:09

I\'ve built a crawler that had to run on about 5M pages (by increasing the url ID) and then parses the pages which contain the info\' I need.

after using an algorith

4条回答
  •  不思量自难忘°
    2020-12-05 02:21

    this turns the recursion in to a loop:

    def checkNextID(ID):
        global numOfRuns, curRes, lastResult
        while ID < lastResult:
            try:
                numOfRuns += 1
                if numOfRuns % 10 == 0:
                    time.sleep(3) # sleep every 10 iterations
                if isValid(ID + 8):
                    parseHTML(curRes)
                    ID = ID + 8
                elif isValid(ID + 18):
                    parseHTML(curRes)
                    ID = ID + 18
                elif isValid(ID + 7):
                    parseHTML(curRes)
                    ID = ID + 7
                elif isValid(ID + 17):
                    parseHTML(curRes)
                    ID = ID + 17
                elif isValid(ID+6):
                    parseHTML(curRes)
                    ID = ID + 6
                elif isValid(ID + 16):
                    parseHTML(curRes)
                    ID = ID + 16
                else:
                    ID = ID + 1
            except Exception, e:
                print "somethin went wrong: " + str(e)
    

提交回复
热议问题