如何在Python中发送多个HTTP请求
我正在使用Python的request.post()
方法向一个远程数据库发送数据。我应该如何在同一个网址上发送多个请求(大约20到30个),并且每个请求的数据都不一样呢?
另外,顺序发送请求可以吗?还是说我需要同时发送这些请求呢?
1 个回答
2
你可以看看 grequests,它是基于 requests 和 gevent 这两个库的。
import grequests
urls = [
'http://www.heroku.com',
'http://python-tablib.org',
'http://httpbin.org',
'http://python-requests.org',
'http://kennethreitz.com'
]
rs = (grequests.get(u) for u in urls)
grequests.map(rs)
[<Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>]