# Twitter Advanced Search Scraper

Collect tweets, likes, retweets, replies, and media automatically. Save hours of manual work and get ready-to-use data to Excel/CSV/JSON in seconds.

- Template page: [https://www.octoparse.com/template/twitter-scraper-by-keywords](https://www.octoparse.com/template/twitter-scraper-by-keywords)
- Categories: Social Media
- Status: `PUBLISHED`
- Run mode: `CLOUD`

## Pricing

Current price: **$0.3/1,000 lines**. Billing is based on output rows; an Octoparse subscription may be required.

## What is an Octoparse template?

An Octoparse template is a ready-to-use scraping workflow with predefined inputs and structured outputs. Use the exact parameter keys below; do not invent parameters.

## Overview

This ready-to-use template collects structured data from search-results pages.

## Output

The current workflow extracts 26 fields, including `Ads`, `Author_Handle`, `Author_Name`, `Author_Web_Page_URL`, `Bookmark_Count`, `Language`, `Like_Count`, `Post_ID`, `Post_URL`, `Query_Str`, `QuoteContent`, `QuoteTwitterURL`, `Reply_Count`, `Reply_to_Whom`, `Reply_to_Whom_Handle`, `Reply_to_Whom_URL`, `Reply_to_Whom_Username`, `Replying_to`, `Repost_Count`, `Tweet_Content`, `Tweet_Image_URL`, `Tweet_URL`, `Type`, `UTC_Time`, `Verified_Status`, `View_Count`.

## Use Cases

- Use structured results for research, comparison, and monitoring.
- Collect rows without building the extraction workflow from scratch.
- Combine results with other templates for downstream enrichment.
- Review a representative result before starting a large batch.

## Why Octoparse

- **No coding required:** complete Dates (From), Dates (To), Max Tweets to Extract and start the template in cloud mode.
- **Flexible export:** review and export results as CSV, Excel, or JSON.

## Input

### Dates (From)

Required. starttime Constraints: minLength=1; maxLength=100.

### Dates (To)

Required. endtime Constraints: minLength=1; maxLength=100.

### Max Tweets to Extract

Required. Max_Items Constraints: minimum=1, maximum=999999999.

### All of these words

Optional. 高级搜索功能中的All of these words Constraints: minLength=0; maxLength=10000.

### This exact phrase

Optional. This exact phrase from https://x.com/search-advanced Constraints: minLength=0; maxLength=10000.

### Any of these words

Optional. 高级搜索功能中的Any of these words Constraints: minLength=0; maxLength=10000.

### None of these words

Optional. 高级搜索功能中的None of these words Constraints: minLength=0; maxLength=10000.

### These hashtags

Optional. 高级搜索功能中的These hashtags Constraints: minLength=0; maxLength=10000.

### From these accounts

Optional. 高级搜索功能中的From these accounts Constraints: minLength=0; maxLength=1000.

### To these accounts

Optional. 高级搜索功能中的To these accounts Constraints: minLength=0; maxLength=1000.

### Mentioning these accounts

Optional. 高级搜索功能中的Mentioning these accounts Constraints: minLength=0; maxLength=1000.

### Minimum replies

Optional. 高级搜索功能中的Minimum replies Constraints: minimum=0, maximum=9999999.

### Minimum likes

Optional. 高级搜索功能中的Minimum likes Constraints: minimum=0, maximum=9999999.

### Minimum reposts

Optional. 高级搜索功能中的Minimum reposts Constraints: minimum=0, maximum=999999.

### Language

Optional. Any keeps all languages. English returns only English tweets. Constraints: minLength=0; maxLength=100. Callable values are the `const` keys in JSON `oneOf`, not the option titles.

### Include "Top" Results

Optional. Switch Off to scrape only the Latest tab. Switch On to scrape both Top and Latest results. Constraints: default=false.

### Cloud Cluster

Optional. Cloud Cluster

### Scraping mode

Required. You no longer need to choose a mode—searches now run in "Day" mode by default for greater precision. Just enter anything. It will be set to day mode automatically. Constraints: items.minLength=1; items.maxLength=1000.

### Reply Filter

Optional. Choose whether to include replies or only scrape replies. Constraints: default=false.

### Include replies and original posts

Optional. Include replies and original posts Constraints: default=false.

### Only show replies

Optional. Only show replies Constraints: default=false.

## How to Use

# Twitter/X Search Scraper

Scrape public Twitter/X posts by advanced-search criteria: dates, words/phrases, hashtags, accounts, mentions, reply/like/repost minimums, language, max tweets, and latest results.

## Before you start

- Use responsibly and respect [Twitter/X's Terms of Service](https://help.x.com/en/rules-and-policies/x-rules).
- Only public tweets are accessible.
- Twitter/X rate limits may apply; handle personal data ethically.
- For large datasets, batch keywords or dates into multiple runs.

## How to use

1. **Start the template.** Click **"Try it!"** to load it.
2. **Fill in parameters.** Enter criteria like on [Twitter/X's Advanced Search page](https://x.com/search-advanced).
   > **Note:** Avoid entering keywords and hashtags at the same time; doing both may disable the date-range filter and lead to duplicate or unexpected results.
3. **Run the scraper.** Click **"Start"**, choose a run mode (greyed-out modes are not supported). Octoparse applies your search query, scrolls results, and extracts matching tweets.
4. **Monitor interruptions.** If a sub-task status is **"Stopped"** (e.g. network glitch), re-run that sub-task. Scraping time depends on tweet count and date range.
5. **Export data.** Review in **"Data Preview"** or output section; export as CSV or Excel.

## Parameters

| Parameter | Required? | Example / notes |
|---|---:|---|
| Dates (From) | Required | `2020-01-01` |
| Dates (To) | Required | `2024-10-15` |
| All of these words | Optional | `what’s happening` · contains both "what's" and "happening" |
| This exact phrase | Optional | `happy hour` · contains exact phrase “happy hour” |
| Any of these words | Optional | `cats dogs` · contains either “cats” or “dogs” (or both) |
| None of these words | Optional | `cats dogs` · contains neither “cats” nor “dogs” |
| These hashtags | Optional | `#ThrowbackThursday` · contains #ThrowbackThursday |
| From these accounts | Optional | `@X` · sent from @X |
| To these accounts | Optional | `@X` · sent in reply to @X |
| Mentioning these accounts | Optional | `@SFBART @Caltrain` · mentions @SFBART or @Caltrain |
| Minimum replies | Optional | `280` · at least 280 replies |
| Minimum likes | Optional | `280` · at least 280 Likes |
| Minimum reposts | Optional | `280` · at least 280 reposts |
| Language | Optional | Any language, `en`, `jp`, `fr`, `de` |
| Max Tweets to Extract | Optional | `100` (number of tweets to scrape) |
| Include "Latest" Results | Optional | Switch Off: Top tab only. Switch On: Top and Latest. |

## Tips

- Use fewer keywords per run for higher accuracy.
- For large datasets, break keywords or dates into multiple runs.

## Limitations

Results depend on what the source site exposes at run time. Fields may be empty when a source page does not provide a value. The template enforces the input limits shown above.

## Tips

Use specific, valid inputs and review a representative result before starting a large batch. Remove duplicate inputs when repeated records are not needed.

## FAQ

### What do I need to enter?

Use the exact inputs and limits listed above.

### What data does this template return?

See Output Schema below; availability can vary by source record.

### How is usage billed?

See the Pricing section above for current pricing and billing details.

## Related Templates

- [Twitter Advanced Search Comments Scraper](https://www.octoparse.com/template/twitter-advanced-search-comments-scraper)
- [Twitter People Search Scraper](https://www.octoparse.com/template/twitter-people-search-scraper)

## Input Schema

```json
{
  "title": "Twitter Advanced Search Scraper input",
  "description": "Input parameters configured for the current published template version.",
  "type": "object",
  "schemaVersion": 1,
  "additionalProperties": false,
  "properties": {
    "dates": {
      "title": "Dates (From)",
      "description": "starttime",
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "dates_2": {
      "title": "Dates (To)",
      "description": "endtime",
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "max_Tweets_to_Extract": {
      "title": "Max Tweets to Extract",
      "description": "Max_Items",
      "type": "integer",
      "minimum": 1,
      "maximum": 999999999,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "all_of_these_words": {
      "title": "All of these words",
      "description": "高级搜索功能中的All of these words",
      "type": "string",
      "minLength": 0,
      "maxLength": 10000,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "this_exact_phrase": {
      "title": "This exact phrase",
      "description": "This exact phrase from https://x.com/search-advanced",
      "type": "string",
      "minLength": 0,
      "maxLength": 10000,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "any_of_these_words": {
      "title": "Any of these words",
      "description": "高级搜索功能中的Any of these words",
      "type": "string",
      "minLength": 0,
      "maxLength": 10000,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "none_of_these_words": {
      "title": "None of these words",
      "description": "高级搜索功能中的None of these words",
      "type": "string",
      "minLength": 0,
      "maxLength": 10000,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "these_hashtags": {
      "title": "These hashtags",
      "description": "高级搜索功能中的These hashtags",
      "type": "string",
      "minLength": 0,
      "maxLength": 10000,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "from_these_accounts": {
      "title": "From these accounts",
      "description": "高级搜索功能中的From these accounts",
      "type": "string",
      "minLength": 0,
      "maxLength": 1000,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "to_these_accounts": {
      "title": "To these accounts",
      "description": "高级搜索功能中的To these accounts",
      "type": "string",
      "minLength": 0,
      "maxLength": 1000,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "mentioning_these_accounts": {
      "title": "Mentioning these accounts",
      "description": "高级搜索功能中的Mentioning these accounts",
      "type": "string",
      "minLength": 0,
      "maxLength": 1000,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "minimum_replies": {
      "title": "Minimum replies",
      "description": "高级搜索功能中的Minimum replies",
      "type": "integer",
      "minimum": 0,
      "maximum": 9999999,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "minimum_likes": {
      "title": "Minimum likes",
      "description": "高级搜索功能中的Minimum likes",
      "type": "integer",
      "minimum": 0,
      "maximum": 9999999,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "minimum_reposts": {
      "title": "Minimum reposts",
      "description": "高级搜索功能中的Minimum reposts",
      "type": "integer",
      "minimum": 0,
      "maximum": 999999,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "language": {
      "title": "Language",
      "description": "Any keeps all languages. English returns only English tweets.",
      "type": "string",
      "minLength": 0,
      "maxLength": 100,
      "oneOf": [
        {
          "title": "any",
          "const": "Any"
        },
        {
          "title": "en",
          "const": "English"
        },
        {
          "title": "zh-cn",
          "const": "Chinese"
        },
        {
          "title": "es",
          "const": "Spanish"
        },
        {
          "title": "ar",
          "const": "Arabic"
        },
        {
          "title": "fr",
          "const": "French"
        },
        {
          "title": "ja",
          "const": "Japanese"
        },
        {
          "title": "de",
          "const": "German"
        },
        {
          "title": "pt",
          "const": "Portuguese"
        },
        {
          "title": "ru",
          "const": "Russian"
        },
        {
          "title": "hi",
          "const": "Hindi"
        },
        {
          "title": "ko",
          "const": "Korean"
        },
        {
          "title": "it",
          "const": "Italian"
        },
        {
          "title": "tr",
          "const": "Turkish"
        },
        {
          "title": "vi",
          "const": "Vietnamese"
        },
        {
          "title": "id",
          "const": "Indonesian"
        },
        {
          "title": "fa",
          "const": "Persian"
        },
        {
          "title": "th",
          "const": "Thai"
        },
        {
          "title": "nl",
          "const": "Dutch"
        },
        {
          "title": "pl",
          "const": "Polish"
        },
        {
          "title": "uk",
          "const": "Ukrainian"
        },
        {
          "title": "ro",
          "const": "Romanian"
        },
        {
          "title": "el",
          "const": "Greek"
        },
        {
          "title": "hu",
          "const": "Hungarian"
        },
        {
          "title": "cs",
          "const": "Czech"
        },
        {
          "title": "sv",
          "const": "Swedish"
        },
        {
          "title": "he",
          "const": "Hebrew"
        },
        {
          "title": "da",
          "const": "Danish"
        },
        {
          "title": "no",
          "const": "Norwegian"
        },
        {
          "title": "fi",
          "const": "Finnish"
        },
        {
          "title": "sk",
          "const": "Slovak"
        },
        {
          "title": "sr",
          "const": "Serbian"
        },
        {
          "title": "bg",
          "const": "Bulgarian"
        },
        {
          "title": "hr",
          "const": "Croatian"
        },
        {
          "title": "ca",
          "const": "Catalan"
        },
        {
          "title": "ur",
          "const": "Urdu"
        },
        {
          "title": "bn",
          "const": "Bangla"
        },
        {
          "title": "ta",
          "const": "Tamil"
        },
        {
          "title": "gu",
          "const": "Gujarati"
        },
        {
          "title": "mr",
          "const": "Marathi"
        },
        {
          "title": "kn",
          "const": "Kannada"
        },
        {
          "title": "ar-x-fm",
          "const": "Arabic (Feminine)"
        },
        {
          "title": "zh-tw",
          "const": "Traditional Chinese"
        }
      ],
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "include_\"Top\"_Results": {
      "title": "Include \"Top\" Results",
      "description": "Switch Off to scrape only the Latest tab. Switch On to scrape both Top and Latest results.",
      "type": "boolean",
      "default": false,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "cloud_Cluster": {
      "title": "Cloud Cluster",
      "description": "Cloud Cluster",
      "type": "string",
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "scraping_mode": {
      "title": "Scraping mode",
      "description": "You no longer need to choose a mode—searches now run in \"Day\" mode by default for greater precision. Just enter anything. It will be set to day mode automatically.",
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 1000
      },
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "reply_Filter": {
      "title": "Reply Filter",
      "description": "Choose whether to include replies or only scrape replies.",
      "type": "boolean",
      "default": false,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "include_replies_and_original_posts": {
      "title": "Include replies and original posts",
      "description": "Include replies and original posts",
      "type": "boolean",
      "default": false,
      "x-octoparse": {
        "apiEnabled": true
      }
    },
    "only_show_replies": {
      "title": "Only show replies",
      "description": "Only show replies",
      "type": "boolean",
      "default": false,
      "x-octoparse": {
        "apiEnabled": true
      }
    }
  },
  "required": [
    "dates",
    "dates_2",
    "max_Tweets_to_Extract",
    "scraping_mode"
  ]
}
```

## Input JSON Example

Example 1

```json
{
  "all_of_these_words": "iphone",
  "dates": "2026-11-01",
  "dates_2": "2026-11-16",
  "max_Tweets_to_Extract": 100,
  "scraping_mode": [
    "day"
  ]
}
```


## Output Schema

```json
{
  "schemaVersion": 1,
  "type": "object",
  "properties": {
    "Ads": {
      "type": "string",
      "description": ""
    },
    "Author_Handle": {
      "type": "string",
      "description": ""
    },
    "Author_Name": {
      "type": "string",
      "description": ""
    },
    "Author_Web_Page_URL": {
      "type": "string",
      "description": ""
    },
    "Bookmark_Count": {
      "type": "string",
      "description": ""
    },
    "Language": {
      "type": "string",
      "description": ""
    },
    "Like_Count": {
      "type": "string",
      "description": ""
    },
    "Post_ID": {
      "type": "string",
      "description": ""
    },
    "Post_URL": {
      "type": "string",
      "description": ""
    },
    "Query_Str": {
      "type": "string",
      "description": ""
    },
    "QuoteContent": {
      "type": "string",
      "description": ""
    },
    "QuoteTwitterURL": {
      "type": "string",
      "description": ""
    },
    "Reply_Count": {
      "type": "string",
      "description": ""
    },
    "Reply_to_Whom": {
      "type": "string",
      "description": ""
    },
    "Reply_to_Whom_Handle": {
      "type": "string",
      "description": ""
    },
    "Reply_to_Whom_URL": {
      "type": "string",
      "description": ""
    },
    "Reply_to_Whom_Username": {
      "type": "string",
      "description": ""
    },
    "Replying_to": {
      "type": "string",
      "description": ""
    },
    "Repost_Count": {
      "type": "string",
      "description": ""
    },
    "Tweet_Content": {
      "type": "string",
      "description": ""
    },
    "Tweet_Image_URL": {
      "type": "string",
      "description": ""
    },
    "Tweet_URL": {
      "type": "string",
      "description": ""
    },
    "Type": {
      "type": "string",
      "description": ""
    },
    "UTC_Time": {
      "type": "string",
      "description": ""
    },
    "Verified_Status": {
      "type": "string",
      "description": ""
    },
    "View_Count": {
      "type": "string",
      "description": ""
    }
  },
  "title": "Twitter Advanced Search Scraper output",
  "description": "Initial output fields derived from the current published implementation. Field descriptions are maintained by Data Center; production field names and types should be refreshed from recent successful runs.",
  "additionalProperties": false
}
```

## Output Example

Example 1

```json
{
  "Ads": "False",
  "Author_Handle": "Steh_Papaiano",
  "Author_Name": "Steh Papaiano",
  "Author_Web_Page_URL": "https://x.com/Steh_Papaiano",
  "Bookmark_Count": "14",
  "Language": "pt",
  "Like_Count": "362",
  "Post_ID": "2121030039143641580",
  "Post_URL": "https://x.com/search?q=iphone%20until%3A2026-11-13_00%3A00%3A00_UTC%20since%3A2026-11-11_00%3A00%3A00_UTC%20-filter%3Areplies&src=typed_query&f=live",
  "Query_Str": "iphone",
  "QuoteContent": "",
  "QuoteTwitterURL": "",
  "Reply_Count": "8",
  "Reply_to_Whom": "",
  "Reply_to_Whom_Handle": "",
  "Reply_to_Whom_URL": "",
  "Reply_to_Whom_Username": "",
  "Replying_to": "False",
  "Repost_Count": "100",
  "Tweet_Content": "Enquanto o brasileiro trabalha pra pagar boleto, Davi Alcolumbre usa o microfone do Senado pra falar do anelzinho antiestresse e justificar iPhone para senador. O contribuinte paga a conta, o marajá reclama da pressão e ainda ganha uma rosca pra relaxar. BRASÍLIA É UM CIRCO, o problema é que os palhaços somos nós.",
  "Tweet_Image_URL": "https://pbs.twimg.com/amplify_video_thumb/2121029556484108288/img/dwjP1xF6UBbRDSUM.jpg",
  "Tweet_URL": "https://x.com/Steh_Papaiano/status/2121030039143641580",
  "Type": "Latest",
  "UTC_Time": "2026-11-12 23:59:02+00:00",
  "Verified_Status": "True",
  "View_Count": "4041"
}
```

## API

`POST https://openapi.octoparse.com/api/agentTools/executeTask`

This is the OpenAPI Agent Tools `executeTask` endpoint. Authenticate with a Bearer token.

Request body:

`templateName` is the template slug; `parameters` is a JSON object string whose keys match Input Schema; `taskName`, `idempotencyKey`, and `maxCollectedRows` are optional.

Obtain a token:

```http
POST https://openapi.octoparse.com/token
Content-Type: application/json

{
  "username": "YOUR_USERNAME",
  "password": "YOUR_PASSWORD",
  "grant_type": "password"
}
```

Use `data.access_token` as `Authorization: Bearer <token>`. After starting, poll `getTaskStatus` and export with `exportData`.

```json
{
  "templateName": "twitter-scraper-by-keywords",
  "taskName": "Twitter Advanced Search Scraper",
  "parameters": "{\"all_of_these_words\":\"iphone\",\"dates\":\"2026-11-01\",\"dates_2\":\"2026-11-16\",\"max_Tweets_to_Extract\":100,\"scraping_mode\":[\"day\"]}"
}
```

## Python Example

```python
import json
import requests

OPENAPI_BASE = "https://openapi.octoparse.com"
ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"

parameters = json.loads("{\"all_of_these_words\":\"iphone\",\"dates\":\"2026-11-01\",\"dates_2\":\"2026-11-16\",\"max_Tweets_to_Extract\":100,\"scraping_mode\":[\"day\"]}")

response = requests.post(
    f"{OPENAPI_BASE}/api/agentTools/executeTask",
    headers={
        "Authorization": f"Bearer {ACCESS_TOKEN}",
        "Content-Type": "application/json",
    },
    json={
        "templateName": "twitter-scraper-by-keywords",
        "taskName": "Twitter Advanced Search Scraper",
        "parameters": json.dumps(parameters, ensure_ascii=False),
    },
    timeout=60,
)
print(response.status_code)
print(response.json())
```

## HTTP/cURL Example

```bash
curl -X POST "https://openapi.octoparse.com/api/agentTools/executeTask" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "templateName": "twitter-scraper-by-keywords",
  "taskName": "Twitter Advanced Search Scraper",
  "parameters": "{\"all_of_these_words\":\"iphone\",\"dates\":\"2026-11-01\",\"dates_2\":\"2026-11-16\",\"max_Tweets_to_Extract\":100,\"scraping_mode\":[\"day\"]}"
}
JSON
```

## MCP Setup

Connect an MCP-compatible AI client to `https://mcp.octoparse.com` using browser OAuth or an Octoparse API key. Find `twitter-scraper-by-keywords`, inspect its inputs, create a cloud task with the exact Input Schema keys, and export JSON results.

## Machine-readable Resources

- [Template contract](https://www.octoparse.com/templates/twitter-scraper-by-keywords.json)
- [Manifest](https://www.octoparse.com/templates/twitter-scraper-by-keywords-manifest.json)
