the last page is not constructed

23 Views Asked by At
def SUM(nums,q,page):
    tmp = 0
    for num in nums:
        tmp += int(num)
    total = q.get()
    total += tmp
    q.put(total)
    print(f'page:{page},page_sum:{tmp},total:{total}')


def main():
    start = time.time()
    #print(f'Task run at {start}')
    session = glidesky_login()
    total = 0
    q = Manager().Queue()
    q.put(total)
    with Pool(processes=10) as pool:
        for page in range(999,1001):
            url = "http://www.glidedsky.com/level/web/crawler-font-puzzle-1?page=" + str(page)
            resp = session.get(url)
            if resp.status_code == 200:
                pool.apply_async(func=SUM,args=(parse_html(resp.text),q,page))
            else:
                print(f'page {page} failed')
    end = time.time()
    print(f'The result is {q.get()},time costs {start-end}')
    

if __name__ == '__main__':
    main()

result: page:999,page_sum:2306,total:2306 The result is 2306,time costs -1.8702850341796875

i want to make a sum of numbers in 1000 pages ,but 1000th page was missing ,so i change the range to (999,1001),it's still missing, maybe i have a wrong recognition there.

it's my first time to question here and your advice will help me a lot. ^.^

0

There are 0 best solutions below