GitHub

安装

pip install gevent grequests
import grequests

urls = [
    'http://www.heroku.com',
    'http://python-tablib.org',
    'http://httpbin.org',
    'http://python-requests.org',
    'http://fakedomain/',
    'http://kennethreitz.com'
]

rs = (grequests.get(u) for u in urls)

reps = grequests.map(rs)

# 添加回调
def exception_handler(request, exception):
    print("Request failed")

reqs = [
   grequests.get('http://httpbin.org/delay/1', timeout=0.001),
   grequests.get('http://fakedomain/'),
   grequests.get('http://httpbin.org/status/500')]
grequests.map(reqs, exception_handler=exception_handler)

相关文章:

  • 2021-11-15
  • 2022-12-23
  • 2021-06-25
  • 2022-01-17
  • 2021-12-29
  • 2022-02-07
  • 2021-11-23
  • 2021-08-05
猜你喜欢
  • 2022-01-21
  • 2021-11-23
  • 2021-11-24
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2021-08-09
相关资源
相似解决方案