Skip to content

About

X (Twitter) scraper API: X (Twitter) Profile, X (Twitter) Search, X (Twitter) Trends as clean JSON. Python examples with requests, Scrapy, asyncio and the DataGuru SDK.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

X (Twitter) Scraper API

Scrape X (Twitter) with a JSON API. This repo has working Python examples for DataGuru's X (Twitter) scraper APIs: X (Twitter) Profile, X (Twitter) Search and X (Twitter) Trends.

DataGuru runs the scraping, proxies, retries and parsing, and returns clean JSON. You pay only for successful requests, from $0.001 per request, out of a prepaid balance: no subscription. New accounts get $1.00 of free credit.

X (Twitter) APIs

API What it returns Price Page
X (Twitter) Profile Get a public X (Twitter) profile: name, handle, bio, followers, following, verified status, and profile picture. $0.0025 https://dataguru.cc/apis/x-profile/
X (Twitter) Search Search X (Twitter) posts and accounts by keyword or query. $0.001 https://dataguru.cc/apis/x-search/
X (Twitter) Trends Get trending hashtags, topics, and discussions on X (Twitter) by country or worldwide. $0.003 https://dataguru.cc/apis/x-trends/

Quick start

  1. Create a free account and an API key at dashboard.dataguru.cc.
  2. Install and run:
git clone https://github.com/dataguru-cc/twitter-scraper-api.git
cd twitter-scraper-api
pip install -r requirements.txt
export DATAGURU_API_KEY="your key"
python examples/sdk_example.py x-profile

Examples

Every example covers all 3 X (Twitter) APIs. Pass an API name to run just one; with no name each script runs them all, and each call is billed at the price above.

File Style Run
examples/sdk_example.py DataGuru Python SDK (pip install dataguru-sdk), one function per API, saves JSON to output/ python examples/sdk_example.py
examples/requests_example.py Plain requests, synchronous python examples/requests_example.py
examples/async_example.py asyncio + httpx, concurrent with a limit python examples/async_example.py
examples/scrapy_spider.py Scrapy spider, items to JSON/CSV scrapy runspider examples/scrapy_spider.py -O x-twitter.json

All requests use the header Authorization: Api-Key YOUR_API_KEY. Errors return {"success": false, "error": {"code", "message", "request_id"}}, with HTTP 402 when the balance runs out and 429 (with Retry-After) when rate limited. Failed requests are not charged.

API reference

X (Twitter) Profile

Get a public X (Twitter) profile: name, handle, bio, followers, following, verified status, and profile picture.

Parameter Type Required Description
profile_url string yes Public X profile URL or username, e.g. https://x.com/elonmusk

Response fields: username, full_name, biography, external_link, follower_count, following_count, total_post_count, account_category, verified_badge, profile_picture_hd_url, unique_id, nickname, total_heart_like_count, video_count, screen_name, location, join_date, verified_type, pinned_tweet_id, plus _metadata

curl -X POST "https://api.dataguru.cc/api/v1/x/profile" \
  -H "Authorization: Api-Key $DATAGURU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"profile_url": "https://x.com/NASA"}'
Response schema

Values are type placeholders from the API's published schema, not real data.

{
  "user_profile": {
    "username": "string",
    "full_name": "string",
    "biography": "string",
    "external_link": "https://example.com/...",
    "follower_count": 0,
    "following_count": 0,
    "total_post_count": 0,
    "account_category": "string",
    "verified_badge": false,
    "profile_picture_hd_url": "https://example.com/...",
    "unique_id": "1234567890",
    "nickname": "string",
    "total_heart_like_count": 0,
    "video_count": 0,
    "screen_name": "string",
    "location": "string",
    "join_date": "2026-01-01T12:00:00Z",
    "verified_type": "Blue",
    "pinned_tweet_id": "1234567890"
  },
  "_metadata": {
    "request_id": "3f6c1a2e-8b4d-4c1e-9a7f-2d5e6b7c8d9e",
    "execution_time_ms": 842,
    "endpoint": "X (Twitter) Profile",
    "mode": "live",
    "format": "json",
    "timestamp": "2026-01-01T12:00:00+00:00"
  }
}

X (Twitter) Search

Search X (Twitter) posts and accounts by keyword or query.

Parameter Type Required Description
limit integer no Maximum number of search results to return (1-50). Default: 5.
query string yes Search query or topic, e.g. "openai" or "AI".

Response fields: query, search_url, total_results, results, plus _metadata

curl -X POST "https://api.dataguru.cc/api/v1/x/search" \
  -H "Authorization: Api-Key $DATAGURU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "openai"}'
Response schema

Values are type placeholders from the API's published schema, not real data.

{
  "x_search": {
    "query": "string",
    "search_url": "https://example.com/...",
    "total_results": 0,
    "results": [
      {
        "post_id": "1234567890",
        "post_url": "https://example.com/...",
        "author_username": "string",
        "author_name": "string",
        "author_id": "1234567890",
        "author_profile_image": "string",
        "text": "string",
        "embedded_hashtags": [
          "string"
        ],
        "create_time": "string",
        "reply_count": 0,
        "retweet_count": 0,
        "like_count": 0,
        "quote_count": 0,
        "view_count": 0,
        "save_count": 0,
        "is_retweet": false,
        "is_pinned": false
      }
    ]
  },
  "_metadata": {
    "request_id": "3f6c1a2e-8b4d-4c1e-9a7f-2d5e6b7c8d9e",
    "execution_time_ms": 842,
    "endpoint": "X (Twitter) Search",
    "mode": "live",
    "format": "json",
    "timestamp": "2026-01-01T12:00:00+00:00"
  }
}

X (Twitter) Trends

Get trending hashtags, topics, and discussions on X (Twitter) by country or worldwide.

Parameter Type Required Description
include_tweets boolean no Whether to include sample tweets for the top trends. Default: False.
limit integer no Maximum number of trending items to return (1-100). Default: 50.
location string no Country name, country code, or "worldwide" (e.g. us, uk, worldwide). Default: worldwide.
tweets_limit integer no Number of sample tweets per trend if include_tweets is true (1-10). Default: 3.

Response fields: location, location_slug, source_url, scraped_at, total_trends, total_hashtags, total_topics, top_hashtags, popular_topics, all_trends, longest_trending, new_trends, hourly_timeline, plus _metadata

curl -X POST "https://api.dataguru.cc/api/v1/x/trends" \
  -H "Authorization: Api-Key $DATAGURU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
Response schema

Values are type placeholders from the API's published schema, not real data.

{
  "x_trends": {
    "location": "string",
    "location_slug": "string",
    "source_url": "https://example.com/...",
    "scraped_at": "2026-01-01T12:00:00Z",
    "total_trends": 0,
    "total_hashtags": 0,
    "total_topics": 0,
    "top_hashtags": [
      {
        "rank": 0,
        "name": "string",
        "type": "hashtag",
        "clean_name": "string",
        "description": "string",
        "post_url": "https://example.com/...",
        "current_rank": 0,
        "peak_rank": 0,
        "hours_trending": 0,
        "rank_change": "string",
        "status": "NEW",
        "tweet_count": "string",
        "sample_tweets": [
          {
            "post_id": "1234567890",
            "post_url": "https://example.com/...",
            "author_username": "string",
            "author_name": "string",
            "author_id": "1234567890",
            "author_profile_image": "string",
            "text": "string",
            "embedded_hashtags": [
              "string"
            ],
            "create_time": "string",
            "reply_count": 0,
            "retweet_count": 0,
            "like_count": 0,
            "quote_count": 0,
            "view_count": 0,
            "save_count": 0,
            "is_retweet": false,
            "is_pinned": false
          }
        ],
        "hashtag": "string",
        "overall_rank": 0
      }
    ],
    "popular_topics": [
      {
        "rank": 0,
        "name": "string",
        "type": "hashtag",
        "clean_name": "string",
        "description": "string",
        "post_url": "https://example.com/...",
        "current_rank": 0,
        "peak_rank": 0,
        "hours_trending": 0,
        "rank_change": "string",
        "status": "NEW",
        "tweet_count": "string",
        "sample_tweets": [
          {
            "post_id": "1234567890",
            "post_url": "https://example.com/...",
            "author_username": "string",
            "author_name": "string",
            "author_id": "1234567890",
            "author_profile_image": "string",
            "text": "string",
            "embedded_hashtags": [
              "string"
            ],
            "create_time": "string",
            "reply_count": 0,
            "retweet_count": 0,
            "like_count": 0,
            "quote_count": 0,
            "view_count": 0,
            "save_count": 0,
            "is_retweet": false,
            "is_pinned": false
          }
        ],
        "topic": "string",
        "overall_rank": 0
      }
    ],
    "all_trends": [
      {
        "rank": 0,
        "name": "string",
        "type": "hashtag",
        "clean_name": "string",
        "description": "string",
        "post_url": "https://example.com/...",
        "current_rank": 0,
        "peak_rank": 0,
        "hours_trending": 0,
        "rank_change": "string",
        "status": "NEW",
        "tweet_count": "string",
        "sample_tweets": [
          {
            "post_id": "1234567890",
            "post_url": "https://example.com/...",
            "author_username": "string",
            "author_name": "string",
            "author_id": "1234567890",
            "author_profile_image": "string",
            "text": "string",
            "embedded_hashtags": [
              "string"
            ],
            "create_time": "string",
            "reply_count": 0,
            "retweet_count": 0,
            "like_count": 0,
            "quote_count": 0,
            "view_count": 0,
            "save_count": 0,
            "is_retweet": false,
            "is_pinned": false
          }
        ]
      }
    ],
    "longest_trending": [
      {
        "rank": 0,
        "name": "string",
        "type": "hashtag",
        "clean_name": "string",
        "description": "string",
        "post_url": "https://example.com/...",
        "current_rank": 0,
        "peak_rank": 0,
        "hours_trending": 0,
        "rank_change": "string",
        "status": "NEW",
        "tweet_count": "string",
        "sample_tweets": [
          {
            "post_id": "1234567890",
            "post_url": "https://example.com/...",
            "author_username": "string",
            "author_name": "string",
            "author_id": "1234567890",
            "author_profile_image": "string",
            "text": "string",
            "embedded_hashtags": [
              "string"
            ],
            "create_time": "string",
            "reply_count": 0,
            "retweet_count": 0,
            "like_count": 0,
            "quote_count": 0,
            "view_count": 0,
            "save_count": 0,
            "is_retweet": false,
            "is_pinned": false
          }
        ]
      }
    ],
    "new_trends": [
      {
        "name": "string",
        "rank": 0,
        "type": "hashtag",
        "post_url": "https://example.com/..."
      }
    ],
    "hourly_timeline": [
      {
        "time": "string",
        "top_trends": [
          "string"
        ]
      }
    ]
  },
  "_metadata": {
    "request_id": "3f6c1a2e-8b4d-4c1e-9a7f-2d5e6b7c8d9e",
    "execution_time_ms": 842,
    "endpoint": "X (Twitter) Trends",
    "mode": "live",
    "format": "json",
    "timestamp": "2026-01-01T12:00:00+00:00"
  }
}

More

License

The example code is MIT licensed. Use of the DataGuru API is subject to the terms of service.

About

X (Twitter) scraper API: X (Twitter) Profile, X (Twitter) Search, X (Twitter) Trends as clean JSON. Python examples with requests, Scrapy, asyncio and the DataGuru SDK.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors