我正在尝试执行大约 100k GET 请求并解析每个请求的响应正文。我认为 grequests 是一个不错的方法,但我遇到了与“打开的文件太多”相关的错误。这是代码:
import grequests
with open("./100k-sites.csv", "r") as f:
urls = ["http://" + line.rstrip() for line in f]
rs = (grequests.get(u, timeout=1) for u in urls)
responses = grequests.map(rs)
for r in responses:
try:
# do something with the response body
except:
pass
有人有这方面的经验吗?我得到的错误是:
requests.packages.urllib3.connection.HTTPConnection object at 0x7f817ab36898>: 无法建立新连接 [Errno 24] 打开的文件太多