Multiple (asynchronous) connections with urllib2 or other http library?

前端 未结 6 1024
耶瑟儿~
耶瑟儿~ 2020-11-29 04:43

I have code like this.

for p in range(1,1000):
    result = False
    while result is False:
        ret = urllib2.Request(\'http://server/?\'+str(p))
               


        
6条回答
  •  死守一世寂寞
    2020-11-29 05:20

    I know this question is a little old, but I thought it might be useful to promote another async solution built on the requests library.

    list_of_requests = ['http://moop.com', 'http://doop.com', ...]
    
    from simple_requests import Requests
    for response in Requests().swarm(list_of_requests):
        print response.content
    

    The docs are here: http://pythonhosted.org/simple-requests/

提交回复
热议问题