# Tokopedia Search Scraper (`andreaszcw/tokopedia-search-scraper`) Actor

Scrape live Tokopedia search results by keyword into clean CSV/JSON product data: name, price, sold count, rating, shop details. Perfect for market research, price monitoring, and competitor analysis in Indonesia's largest marketplace.

- **URL**: https://apify.com/andreaszcw/tokopedia-search-scraper.md
- **Developed by:** [andreas zico wijaya](https://apify.com/andreaszcw) (community)
- **Categories:** E-commerce
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$50.00 / 1,000 scraped products

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Tokopedia Search Scraper

Scraper produk Tokopedia berbasis endpoint GraphQL publik yang dipakai
aplikasi iOS Tokopedia (`searchProductV5`). Tanpa browser, tanpa login,
tanpa API key. Mendukung proxy residential (123Proxy) dan jalan sebagai
Apify Actor maupun CLI standalone di RDP/VPS.

### Cara kerja

- `POST https://gql.tokopedia.com/graphql/SearchResult/getProductResult`
  dengan operasi `searchProductV5`, variabel `params` berupa string
  parameter URL-encoded (keyword, halaman, filter harga/rating) dan
  header aplikasi iOS (fingerprint acak per request).
- Paginasi mengikuti `additionalParams` dari header respons sampai
  `max_results` tercapai atau halaman habis; produk di-dedupe per
  `product_id`; tiap halaman di-retry 1x bila gagal/timeout.

### File

| File | Fungsi |
|---|---|
| `tokopedia.py` | Modul inti: `search(keyword, max_results, min_price, max_price, min_rating, use_proxy, proxy_port)` |
| `run.py` | CLI standalone (RDP/VPS/lokal) → JSON/CSV |
| `main.py` | Apify Actor (fallback lokal bila SDK tidak ada) |
| `.actor/input_schema.json` | Schema input Apify |
| `apify.json`, `Dockerfile` | Kemasan Apify Actor |
| `requirements.txt` | `curl_cffi`, `requests` (apify hanya di Docker) |
| `install.sh` | Setup sekali jalan di RDP Ubuntu |
| `test_direct.py` | Tes validasi awal (pakai library tokopaedi) |

### Pakai di RDP (standalone)

```bash
bash install.sh
export PROXY_USER='<username-123proxy>'
export PROXY_PASS='<password-123proxy>'
## PROXY_PORT opsional; kosong = rotasi acak port 10535-10559 per request

./venv/bin/python run.py --keyword handphone --max-results 20
./venv/bin/python run.py --keyword laptop --min-price 1000000 --max-price 5000000 --output hasil.csv
./venv/bin/python run.py --keyword "kopi arabika" --max-results 50 --no-proxy --output hasil.json
```

Tanpa `PROXY_USER`/`PROXY_PASS` (atau dengan `--no-proxy`), request
dikirim direct. Direct dari IP datacenter biasanya tetap jalan untuk
volume kecil; untuk volume besar pakai proxy.

### Pakai sebagai Apify Actor

```bash
apify push          # dari folder ini (butuh Apify CLI + login)
```

atau build Docker manual:

```bash
docker build -t tokopedia-search-scraper .
docker run -e PROXY_USER=... -e PROXY_PASS=... tokopedia-search-scraper
```

Input Actor: `keyword` (wajib), `max_results` (default 100),
`min_price`, `max_price`, `min_rating` (0–5), `use_proxy` (default
true). Set `PROXY_USER`/`PROXY_PASS` sebagai secret di Apify Console
(bagian Environment variables). Output: satu item dataset per produk.

Mode lokal tanpa SDK: buat `INPUT.json` di folder ini lalu
`python main.py` — hasil ke `output.json` + JSON per baris di stdout.

### Format output produk

```json
{
  "product_id": 104011674128,
  "name": "realme Note 80 4GB+4GB*|64GB ...",
  "url": "https://www.tokopedia.com/...",
  "price": 1979100,
  "price_original": 2199000,
  "price_text": "Rp1.979.100",
  "sold_count": 286,
  "rating": 4.9,
  "category": "Handphone",
  "image": "https://images.tokopedia.net/...",
  "shop": {
    "id": 123456,
    "name": "realme Official Indonesia",
    "city": "Jakarta Pusat",
    "url": "https://www.tokopedia.com/realme",
    "type": "Mall"
  }
}
```

### Atribusi

Pendekatan query GraphQL + format parameter + struktur fingerprint
diadaptasi dari library **[tokopaedi](https://github.com/hilmiazizi/tokopaedi)**
oleh Hilmi Azizi, berlisensi **MIT License**. Modul `tokopedia.py` di
repo ini ditulis ulang dari nol (query minimal hanya `searchProductV5`,
fingerprint dan user-id digenerate sendiri) dan tidak mengimpor
tokopaedi. Terima kasih kepada penulis aslinya.

### Catatan

- Tokopedia bisa mengubah skema GraphQL sewaktu-waktu; bila query
  gagal total, cek dulu apakah field `searchProductV5` masih ada.
- Jangan hardcode kredensial proxy di file apa pun — selalu via
  environment variable.
- Patuhi ToS Tokopedia dan gunakan data secara wajar (rate wajar,
  jangan membanjiri endpoint).

# Actor input Schema

## `keyword` (type: `string`):

Kata kunci pencarian produk (mis. handphone, laptop, kopi arabika).

## `max_price` (type: `integer`):

Harga maksimum dalam Rupiah (opsional).

## `max_results` (type: `integer`):

Jumlah maksimum produk yang diambil.

## `min_price` (type: `integer`):

Harga minimum dalam Rupiah (opsional).

## `min_rating` (type: `number`):

Rating toko minimum 0-5 (opsional).

## `use_proxy` (type: `boolean`):

Pakai proxy residential 123Proxy (butuh env PROXY_USER / PROXY_PASS). Bila mati, request direct.

## Actor input object example

```json
{
  "max_results": 100,
  "use_proxy": true
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("andreaszcw/tokopedia-search-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("andreaszcw/tokopedia-search-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call andreaszcw/tokopedia-search-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,andreaszcw/tokopedia-search-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/wXSv663eTTrPQNvUO/builds/JHbAqz54TXvhmdNYf/openapi.json
