Python - Example of urllib2 asynchronous / threaded request using HTTPS

前端 未结 5 1472
梦谈多话
梦谈多话 2021-02-02 13:50

I\'m having a heck of a time getting asynchronous / threaded HTTPS requests to work using Python\'s urllib2.

Does anyone out there have a basic example that implements u

5条回答
  •  青春惊慌失措
    2021-02-02 14:31

    You can use asynchronous IO to do this.

    requests + gevent = grequests

    GRequests allows you to use Requests with Gevent to make asynchronous HTTP Requests easily.

    import grequests
    
    urls = [
        'http://www.heroku.com',
        'http://tablib.org',
        'http://httpbin.org',
        'http://python-requests.org',
        'http://kennethreitz.com'
    ]
    
    rs = (grequests.get(u) for u in urls)
    grequests.map(rs)
    

提交回复
热议问题