Tweepy - 多用户搜索
Tweepy - Multiple User Search
尝试执行我认为是非常基本的练习。我有一个包含 7000 多个客户的列表,我想从 Twitter 导入他们的一些属性。我想弄清楚如何在我的 tweepy 查询中输入多个用户名,但我在下面没有任何运气。
#!/usr/bin/python
import tweepy
import csv #Import csv
import os
# Consumer keys and access tokens, used for OAuth
consumer_key = 'MINE'
consumer_secret = 'MINE'
access_token = 'MINE'
access_token_secret = 'MINE'
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Open/Create a file to append data
csvFile = open('ID.csv', 'a')
#Use csv Writer
csvWriter = csv.writer(csvFile)
users = ('IBM' or 'massmutual')
user = api.get_user(screen_name = users)
csvWriter.writerow([user.screen_name, user.id, user.followers_count, user.description.encode('utf-8')])
print user.id
csvFile.close()
你必须在循环中进行,你将制作用户列表并在循环中一个接一个地获取用户实例。
#!/usr/bin/python
import tweepy
import csv #Import csv
import os
# Consumer keys and access tokens, used for OAuth
consumer_key = 'MINE'
consumer_secret = 'MINE'
access_token = 'MINE'
access_token_secret = 'MINE'
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Open/Create a file to append data
csvFile = open('ID.csv', 'a')
#Use csv Writer
csvWriter = csv.writer(csvFile)
users = ['IBM','massmutual','user3',.......]
for user_name in users:
user = api.get_user(screen_name = user_name)
csvWriter.writerow([user.screen_name, user.id, user.followers_count, user.description.encode('utf-8')])
print user.id
csvFile.close()
尝试执行我认为是非常基本的练习。我有一个包含 7000 多个客户的列表,我想从 Twitter 导入他们的一些属性。我想弄清楚如何在我的 tweepy 查询中输入多个用户名,但我在下面没有任何运气。
#!/usr/bin/python
import tweepy
import csv #Import csv
import os
# Consumer keys and access tokens, used for OAuth
consumer_key = 'MINE'
consumer_secret = 'MINE'
access_token = 'MINE'
access_token_secret = 'MINE'
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Open/Create a file to append data
csvFile = open('ID.csv', 'a')
#Use csv Writer
csvWriter = csv.writer(csvFile)
users = ('IBM' or 'massmutual')
user = api.get_user(screen_name = users)
csvWriter.writerow([user.screen_name, user.id, user.followers_count, user.description.encode('utf-8')])
print user.id
csvFile.close()
你必须在循环中进行,你将制作用户列表并在循环中一个接一个地获取用户实例。
#!/usr/bin/python
import tweepy
import csv #Import csv
import os
# Consumer keys and access tokens, used for OAuth
consumer_key = 'MINE'
consumer_secret = 'MINE'
access_token = 'MINE'
access_token_secret = 'MINE'
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Open/Create a file to append data
csvFile = open('ID.csv', 'a')
#Use csv Writer
csvWriter = csv.writer(csvFile)
users = ['IBM','massmutual','user3',.......]
for user_name in users:
user = api.get_user(screen_name = user_name)
csvWriter.writerow([user.screen_name, user.id, user.followers_count, user.description.encode('utf-8')])
print user.id
csvFile.close()