【发布时间】:2019-08-23 22:41:47
【问题描述】:
我第一次使用 tweepy twitter API,需要一些帮助...在下面的代码块中,我循环遍历用户 ID 列表(存储为“帐户”)和每个帐户我正在使用 tweepy.Cursor 来查找他们关注的 ID 列表(他们的“朋友”)。我检查与我关注的帐户的匹配项(存储在“ids”中),然后将匹配项存储为数据框。
我遇到的问题是我不断收到“达到速率限制”错误。请问如何避免这种情况?我假设有一种更聪明的方法可以做到这一点!
谢谢。
df_list = []
for account in accounts:
friends = []
for page in tweepy.Cursor(api.friends_ids, id=account).pages():
friends.extend(page)
friends = pd.Series(friends)
matches = friends[friends.isin(ids)]
d = {'friend_id' : account, 'common_friends' : matches}
matches = pd.DataFrame(data=d)
df_list.append(matches)
final_df = pd.concat(df_list)
【问题讨论】:
-
@ralex 我以前看过那个帖子,但我不明白解决方案。我觉得我的 tweepy/python 体验还处于早期阶段。