我写了一个代码来为twitter上的id列表挑选朋友。 但是API问题使得这段代码非常慢。 有可能改善吗? 我的代码是:
import tweepy
consumer_key = ''
consumer_key_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_key_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True)
for cara in fin1:
if cara in dici1.keys(): next
else:
amigos=[]
for user in tweepy.Cursor(api.friends, screen_name=cara).items():
time.sleep(60)
try:
amigos.append(user.screen_name)
comum = [pessoa for pessoa in amigos if pessoa in fin1]
dici = {cara : comum}
dici1.update(dici)
except: time.sleep(60), next
fin1
是ID列表(用户名,共39个)
dici1
是dict,是我存储信息的地方
删除
time.sleep
调用,这不是必需的,您还有一些根本没有意义的东西,比如那些next
相关问题 更多 >
编程相关推荐