5 minutes

How to Search Tweets by Keyword

Use advanced search operators to find tweets by keyword, hashtag, author, date range, language, and more.

1

Get your API key

Sign up at scrapebadger.com and grab your API key from the dashboard.

2

Basic keyword search

Search for tweets containing a keyword or phrase.

from scrapebadger import ScrapeBadger

sb = ScrapeBadger(api_key="YOUR_API_KEY")
results = sb.twitter.tweets.advanced_search(
    query="web scraping",
    query_type="Latest"
)

for t in results["data"]:
    print(f"@{t['author']['username']}: {t['text'][:100]}")
3

Use advanced operators

Combine operators for precise filtering: from:, since:, lang:, min_faves:, etc.

# Tweets from a specific user with high engagement
results = sb.twitter.tweets.advanced_search(
    query='from:elonmusk min_faves:1000 since:2025-01-01 lang:en',
    query_type="Top"
)
4

Get different result types

Choose between Top (relevance), Latest (chronological), or Media (images/videos).

# Get media tweets only
media = sb.twitter.tweets.advanced_search(
    query="web scraping tutorial",
    query_type="Media"
)
5

Paginate for more results

Use the cursor to get additional pages of search results.

all_tweets = []
cursor = None

for page in range(5):  # Get 5 pages
    result = sb.twitter.tweets.advanced_search(
        query="web scraping API",
        query_type="Latest",
        cursor=cursor
    )
    all_tweets.extend(result["data"])
    cursor = result.get("next_cursor")
    if not cursor:
        break

print(f"Found {len(all_tweets)} tweets")

Frequently Asked Questions

Twitter search covers approximately 7-10 days. For older tweets, you need to use specific tweet or user timeline endpoints.

All Twitter advanced search operators: from:, to:, since:, until:, lang:, min_faves:, min_retweets:, filter:media, -filter:replies, and boolean operators (AND, OR).

Yes. Wrap phrases in quotes: "web scraping API" will match the exact phrase, not individual words.

Use the minus operator: "web scraping -spam" excludes tweets containing "spam". Also: -filter:replies removes replies.