grequests - 前几个响应 200 然后 403
grequests - first couple of responses 200 then 403
我已经从 Interpol website 收集了 link 通缉犯。大约有 10k links。一个一个地抓取需要几个小时,所以我正在寻找使用 grequests
异步完成它的方法。
这是我的 link 列表的预览:
final_links[:20]
['https://www.interpol.int/notice/search/wanted/2009-19572',
'https://www.interpol.int/notice/search/wanted/2015-74196',
'https://www.interpol.int/notice/search/wanted/2014-37667',
'https://www.interpol.int/notice/search/wanted/2011-30019',
'https://www.interpol.int/notice/search/wanted/2009-34171',
'https://www.interpol.int/notice/search/wanted/2012-334072',
'https://www.interpol.int/notice/search/wanted/2012-334068',
'https://www.interpol.int/notice/search/wanted/2012-334070',
'https://www.interpol.int/notice/search/wanted/2013-26064',
'https://www.interpol.int/notice/search/wanted/2013-2528',
'https://www.interpol.int/notice/search/wanted/2014-32597',
'https://www.interpol.int/notice/search/wanted/2013-23413',
'https://www.interpol.int/notice/search/wanted/2010-42146',
'https://www.interpol.int/notice/search/wanted/2015-30555',
'https://www.interpol.int/notice/search/wanted/2013-2514',
'https://www.interpol.int/notice/search/wanted/2010-53288',
'https://www.interpol.int/notice/search/wanted/2015-58805',
'https://www.interpol.int/notice/search/wanted/2015-58807',
'https://www.interpol.int/notice/search/wanted/2015-58803',
'https://www.interpol.int/notice/search/wanted/2015-62307']
因为现在我正试图从每个 link:
获得响应
unsent_request = (grequests.get(url) for url in final_links)
results = grequests.map(unsent_request)
前几个结果是响应 200,但大多数(虽然不是全部)是 403。是国际刑警组织服务器不允许这样做还是我做错了什么(我太贪心了吗? :))?当我用 requests
一个一个地进行时,它工作正常。
这很可能是由于他们的网站保护。您实际上是在以编程方式向他们发送垃圾邮件。所以他们让你做一些请求,然后给你一个 403 forbidden for being a bad boy。您可以简单地检查 return 状态代码,然后在 403 上做一个小睡眠,然后再次尝试请求,每次都增加睡眠,直到您再次恢复正常。或者您可以通过 tor 执行请求,并在收到 403 以获取新的出口节点后继续更改电路。
我已经从 Interpol website 收集了 link 通缉犯。大约有 10k links。一个一个地抓取需要几个小时,所以我正在寻找使用 grequests
异步完成它的方法。
这是我的 link 列表的预览:
final_links[:20]
['https://www.interpol.int/notice/search/wanted/2009-19572',
'https://www.interpol.int/notice/search/wanted/2015-74196',
'https://www.interpol.int/notice/search/wanted/2014-37667',
'https://www.interpol.int/notice/search/wanted/2011-30019',
'https://www.interpol.int/notice/search/wanted/2009-34171',
'https://www.interpol.int/notice/search/wanted/2012-334072',
'https://www.interpol.int/notice/search/wanted/2012-334068',
'https://www.interpol.int/notice/search/wanted/2012-334070',
'https://www.interpol.int/notice/search/wanted/2013-26064',
'https://www.interpol.int/notice/search/wanted/2013-2528',
'https://www.interpol.int/notice/search/wanted/2014-32597',
'https://www.interpol.int/notice/search/wanted/2013-23413',
'https://www.interpol.int/notice/search/wanted/2010-42146',
'https://www.interpol.int/notice/search/wanted/2015-30555',
'https://www.interpol.int/notice/search/wanted/2013-2514',
'https://www.interpol.int/notice/search/wanted/2010-53288',
'https://www.interpol.int/notice/search/wanted/2015-58805',
'https://www.interpol.int/notice/search/wanted/2015-58807',
'https://www.interpol.int/notice/search/wanted/2015-58803',
'https://www.interpol.int/notice/search/wanted/2015-62307']
因为现在我正试图从每个 link:
获得响应unsent_request = (grequests.get(url) for url in final_links)
results = grequests.map(unsent_request)
前几个结果是响应 200,但大多数(虽然不是全部)是 403。是国际刑警组织服务器不允许这样做还是我做错了什么(我太贪心了吗? :))?当我用 requests
一个一个地进行时,它工作正常。
这很可能是由于他们的网站保护。您实际上是在以编程方式向他们发送垃圾邮件。所以他们让你做一些请求,然后给你一个 403 forbidden for being a bad boy。您可以简单地检查 return 状态代码,然后在 403 上做一个小睡眠,然后再次尝试请求,每次都增加睡眠,直到您再次恢复正常。或者您可以通过 tor 执行请求,并在收到 403 以获取新的出口节点后继续更改电路。