简体   繁体   English

用tweepy解决速率限制异常

[英]Solving the rate limit exception with tweepy

I'm using tweepy to scrap twitter. 我正在使用tweepy Twitter。 I need to fetch the entire followers of a user but of course I get a rate limit exception. 我需要获取用户的整个关注者,但是我当然会获得速率限制例外。 I saw that i should use the Cursor object to iterate through all the friends/followers of a user. 我看到我应该使用Cursor对象遍历用户的所有朋友/关注者。 But is there any possibility to select a range of pages? 但是有可能选择一系列页面吗? So on one day I get the data of page 1-10 then in the next day the next 10 page ... etc. Is that possible? 因此,有一天我会获得第1-10页的数据,然后在第二天获得下一页10的数据……等等。这可能吗? or is there a different trick to get over the rate limit thing? 还是有另一种技巧来克服速率限制问题?

I'm not sure how to use tweepy , but when you query a list with the Twitter API and this list is incomplete, the JSON object returned by the Twitter API comes with the attribute next_cursor set to a value different than zero. 我不确定如何使用tweepy ,但是当您使用Twitter API查询列表且此列表不完整时,Twitter API返回的JSON对象带有属性next_cursor设置为零值。

All you have to do is repeat that query including a param cursor in the POST request with the value of next_cursor that you got in the last one and repeat the process until next_cursor comes 0. 您要做的就是重复该查询,在POST请求中包括上一个在上一个中next_cursor值的参数cursor ,并重复该过程直到next_cursor 0。

By the way, according to the documentation , you are allowed to do up to 350 requests per hour to the Twitter API, so you don't really have to wait until the next day. 顺便说一下, 根据文档每小时允许您最多对Twitter API进行350个请求,因此您实际上不必等到第二天。 I suppose you can workaround this limit if you have multiple IP addresses. 我想如果您有多个IP地址,则可以解决此限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM