获取包含特定词汇的所有Twitter用户资料列表
大家好,我正在做一个研究项目,想要获取所有Twitter用户的个人资料(或者至少是其中的一部分用户)。
从这些数据中,我想把所有在个人简介或描述中包含特定单词的用户信息存储到一个文件里。
这是我写的代码,我一直在尝试使用它:
import tweepy
import csv
ckey ='...'
csecret ='...'
atoken = '...'
asecret = '...'
# Attributes of a twitter user profile (this header is already on my file)
twitter_datafile_attr = ['follow_request_sent', 'profile_use_background_image', 'contributors_enabled', 'id', 'verified',
'profile_image_url_https', 'profile_sidebar_fill_color', 'profile_text_color', 'followers_count',
'profile_sidebar_border_color', 'id_str', 'default_profile_image', 'listed_count' 'is_translation_enabled',
'utc_offset', 'statuses_count', 'description', 'friends_count', 'location', 'profile_link_color',
'profile_image_url', 'notifications', 'geo_enabled', 'profile_background_color', 'profile_banner_url',
'profile_background_image_url',
'screen_name', 'lang', 'following', 'profile_background_tile', 'favourites_count', 'name', 'url', 'created_at',
'profile_background_image_url_https', 'time_zone', 'protected', 'default_profile', 'is_translator']
#Authencation
auth = tweepy.OAuthHandler(ckey,csecret)
auth.set_access_token(atoken,asecret)
api=tweepy.API(auth)
# search for people who have both the words "hawaii and "water" anywhere in their bios
user=api.search('hawaii water')
现在我遇到了一些困难,我试着用get_user(ctr)来获取用户信息,其中ctr是一个数字,表示Twitter用户的ID。把数据处理成csv文件很简单,我已经写好这部分代码了。
我是不是应该手动在twitter.com上搜索,然后查看源代码文件,用正则表达式解析数据,还是有其他方法可以用tweepy获取符合特定单词的用户资料呢?
任何帮助都非常感谢。谢谢!
1 个回答
3
我自己找到了答案。
你可以用 api.search_users(query) 这个方法来搜索和某个关键词匹配的用户名。