我一直在尝试提取用户的图片,但截至目前只能提取2张图片。我无法找到我的错误。
oauth = OAuth1(CONSUMER_KEY,
client_secret = CONSUMER_SECRET,
resource_owner_key = OAUTH_TOKEN,
resource_owner_secret = OAUTH_TOKEN_SECRET)
tend = 'https://api.twitter.com/1.1/search/tweets.json?q=from%3Anarendramodi%20filter%3Aimages&src=typd'
response = requests.get(tend, auth = oauth)
tweets = response.json()
links = []
for i in range(len(tweets['statuses'])):
if 'media' in tweets['statuses'][i]['entities']:
for j in range(len(tweets['statuses'][i]['entities']['media'])):
links.append(tweets['statuses'][i]['entities']['media'][j]['media_url'])
以下代码为我提供了一个仅包含2个链接的列表。我不知道这里的问题是什么 P.S当我使用tweepy时,我只能获得17个链接 这是
的代码auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
for status in tweepy.Cursor(api.search, q = 'from:narendramodi filter:images', include_entities=True).items(5000):
if 'media' in status.entities:
for image in status.entities['media']:
f.write(image['media_url'] + '\n')
f.close()
先谢谢