如何解决使用 tweepy 超过限制抓取推文
我创建了一个代码来抓取特定 Twitter 帐户的推文(并将它们存储在 csv 文件中),但无论 Twitter 帐户是什么,我获得的推文数量始终受到限制:
import tweepy
import csv
# Authenticate to Twitter
auth = tweepy.OAuthHandler("")
auth.set_access_token("")
# Create API object
api = tweepy.API(auth,wait_on_rate_limit=True)
try:
api.verify_credentials()
print("Authentication OK")
except:
print("Error during authentication")
userID = "Reuters"
tweetCount = 200
with open(f"tweepy_{userID}.csv",'w',encoding='utf_8_sig') as csv_file:
w = csv.writer(csv_file,lineterminator='\n')
header = ['created_at','text','fav','retweet']
w.writerow(header)
tweets = api.user_timeline(id=userID,count=tweetCount,include_rts = False,tweet_mode = 'extended')
T1 = [[i.created_at,i.full_text.encode("utf-8").decode("utf-8"),i.favorite_count,i.retweet_count] for i in tweets]
for r in T1:
w.writerow(r)
all_tweets = []
all_tweets.extend(tweets)
oldest_id = tweets[-1].id
while True:
tweets = api.user_timeline(id=userID,tweet_mode = 'extended',max_id = oldest_id - 1,)
for i in tweets:
# printing the text stored inside the tweet object
print(i.created_at,i.retweet_count)
T = [i.created_at,i.retweet_count]
row = T
w.writerow(row)
all_tweets.extend(T)
if len(tweets) == 0:
break
oldest_id = tweets[-1].id
print('N of tweets downloaded till now {}'.format(len(all_tweets)))
我想知道是否有可能调整代码(或新代码),以便获得更多的推文
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。