我是python的初学者,这是我所做的并且想用python做的事情:我在tweeter中搜索了一个hashtag并保存了使用hashtag的用户,现在我的问题是如何将这些用户保存为列表,因为我想稍后找到这些用户的关注。 这是我的代码:
for i in tweepy.Cursor(api.search, q="#hashtag").items():
author = i.author.id
tweet = i.text.replace('\n',' ').replace('\r',' ').replace('\r\n',' ')
谢谢!
答案 0 :(得分:0)
我建议:
hashtag_search_results = tweepy.Cursor(api.search, q="#hashtag")
authors = []
for i in hashtag_search_results.items():
author = i.author.id
tweet = i.text.replace('\n',' ').replace('\r',' ').replace('\r\n',' ')
authors.append(author)
# work with the authors list
答案 1 :(得分:0)
为此,您可以使用集合https://docs.python.org/3.6/library/stdtypes.html#set。你可以使用这样的东西:
hashtag_search_results = tweepy.Cursor(api.search, q="#hashtag")
authors = set()
for i in hashtag_search_results.items():
author = i.author.id
tweet = i.text.replace('\n',' ').replace('\r',' ').replace('\r\n',' ')
authors.add(author)
if len(authors) == 100:
break
# work with the authors set