2017-03-20 5 views
0

私はpythonの初心者です。ここで私がやったことは、pythonでやりたかったのです:私はtweeterでハッシュタグを探し、hashtagを使ったユーザーを保存しました。質問は後でこれらのユーザーのフォローを見つけたいので、これらのユーザーをリストとして保存する方法です。twitterでユーザーを見つけてリストとして保存する

for i in tweepy.Cursor(api.search, q="#hashtag").items(): 
    author = i.author.id 
    tweet = i.text.replace('\n',' ').replace('\r',' ').replace('\r\n',' ') 

ありがとう: はここに私のコードです!

+2

コードを入力してください。 tweepy.Cursor(api.search、q = "#hashtag")内のiのために –

+0

を入力してください:items:): author = i.author.id tweet = i.text.replace( '\ n'、 '')。 。replace( '\ r'、 '')。replace( '\ r \ n'、 '') –

答えて

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 
+0

私は100人の著者のリストを私に与えてくれるのではないかと思います。 –

+0

彼らは舗装することはできません。それは '' 'set''です! :) –

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 
+0

お寄せいただきありがとうございます。今私は著者のリストを100に制限したいと思います。私は100人の著者を得た後にそれを止めるのに必要なすべての著者を見つけるのにこのループは必要ありませんが、これは著者がリストの中で繰り返されるべきでないことを意味します最後に100種類のIDのリストが必要です。 –

+0

下記のコメントを参照 –

関連する問題