LoginSignup
0
4

More than 1 year has passed since last update.

tweepyでツイートを取得

Last updated at Posted at 2022-06-17

1. はじめに

目的:twitter APIでツイートを取得する
pythonのtweepyというライブラリを使う.
pip install tweepy
twitter API V2は登録済みで話を進める.
V2では過去約7日分くらい(もうちょっと取得できるときもある)を取得可能.
ただ、15分単位で取得数に限度あり.

2. 検索クエリ

searchkey = '"スマホ" iphone apple -filter:retweets'
tweets = tweepy.Cursor(api.search_tweets,q=searchkey,lang='ja').items(2000)

q:検索したいワードを入れる.
上記の例だと、スマホ AND iphone AND apple AND リツーイトではない
lang:検索に対象の言語(ja:日本語、en:英語、 etc...)
items() : 取得ツイート数

qについてもう少し詳しく書く

構文 内容
'iphone' iphone,IPHONE,アイフォンなど様々な変換されたワードで検索
'スマホ iphone' 単語と単語の間が空白だとAND検索
'スマホ OR iphone' OR検索
'-filter:retweets' リツイートを除外
'-iphone' iphoneが入っているtweetを除外
"ipone" 完全一致ワードの検索
0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4