# Goofish (Xianyu) Search Scraper (`ready_ruler/xianyu-goofish-search`) Actor

Collect public second-hand product listings from Goofish search using a user-provided authenticated session.

- **URL**: https://apify.com/ready_ruler/xianyu-goofish-search.md
- **Developed by:** [lixiaolong](https://apify.com/ready_ruler) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## 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

## Goofish (Xianyu) Search Scraper

Browser-assisted Actor that collects public second-hand product listings from Goofish search. Camoufox handles browser fingerprints; the page itself creates signed mtop requests. The Actor extracts product cards from the rendered DOM and writes normalized records to the default Dataset.

**On the Apify cloud the Actor runs anonymously**: the container environment (limited permissions, `disable_browser_sandbox` auto-enabled) passes the fingerprint wall and the search API accepts the request without a logged-in session, returning real public listings. This is the primary selling point — no cookies, no accounts, no session setup.

### Quick start (Apify cloud)

1. Open the Actor in [Apify Console](https://console.apify.com).
2. Set `keyword` (e.g. `iphone`, `sneakers`, `camera`).
3. Optionally set `maxItems` (default 100) and `maxPages` (default 3).
4. **Start run.** Results land in the default Dataset.

### MCP / AI agent usage

The Actor is available to AI agents through the [Apify MCP server](https://docs.apify.com/mcp.md) and [Apify AGI](https://agi.apify.com) (agentic payments via x402 / MPP):

```json
{
  "tool": "callActor",
  "actor": "ready_ruler/xianyu-goofish-search",
  "input": { "keyword": "iphone", "maxItems": 100 }
}
```

### Authentication requirement (local development only)

On a local machine (no Apify container) Goofish search is **not reliably anonymous** — the API can return `RGV587_ERROR` with a `mini_login` URL even after the fingerprint check passes. Use your own logged-in session through one of these inputs:

1. Local development: `python -m src.login`, then scan `output/login-qr.png` with the Xianyu app. The session is saved to `secrets/goofish-session.json`.
2. Apify input: `cookieHeader` for one session or `cookieHeaders` for your own session pool.
3. Apify input: `storageState`, the JSON object generated by the QR login command.

Do not put credentials in source files. `secrets/`, `output/` and `storage/` are ignored by git.

### Local setup on this machine

```bash
cd /srv/samba/share/deepseek-harees/actors/xianyu-goofish
source ~/.venvs/actor/bin/activate
python -m src.login       # scan the QR and confirm on your phone
python -m unittest discover -s tests -v
python -m src.main
apify run --input-file /tmp/d3-input.json   # Simulated Apify env, EXIT:0
```

Default local input is read from `storage/key_value_stores/default/INPUT.json`. Output is written to `storage/datasets/default/`, and the run summary to `storage/key_value_stores/default/SUMMARY` (Apify SDK 4 local storage does not append `.json` to values created with `set_value`). Raw first responses for parser debugging are saved under `output/search-attempt-*.json`.

### Input example

```json
{
  "keyword": "iphone",
  "maxPages": 3,
  "maxItems": 100,
  "requestDelaySecs": 3
}
```

### Output fields

`itemId`, `title`, `price`, `sellerNick`, `location`, `images`, `publishTime`, `itemUrl`, `soldFlag`, `status`, `wantCount`, and `keyword`.

> Note: the Goofish mtop search endpoint only returns page chrome (bucketId,
> trackParams, etc.). The actual product cards are client-rendered, so the
> Actor extracts them from the rendered DOM. `sellerNick`, `condition` and
> `wantCount` are read from the card markup; `wantCount` can be empty for a
> small fraction of cards that do not display a "人想要" badge (e.g. brand-new
> items whose card omits the badge). `location`/`publishTime` are populated
> only by the dedicated item-detail endpoint, not by search.

The source mtop schema can change. The parser accepts both direct item records and `itemDO` wrappers and deduplicates records by item ID.

### Run behavior

- Up to three fresh browser attempts for token/session failures.
- Explicit `LoginRequiredError` instead of silently returning an empty Dataset.
- Scroll-based loading of subsequent search batches, capped by `maxPages` and `maxItems`.
- Optional Apify proxy configuration.
- No request-signature forgery: requests originate from the loaded Goofish page.

### Demo screenshots

| Input configuration | Live dataset output |
|---|---|
| ![Input](docs/demo-input.png) | ![Dataset](docs/demo-dataset.png) |

| Card grid | MCP / agent call |
|---|---|
| ![Cards](docs/demo-cards.png) | ![MCP](docs/demo-mcp.png) |

### Cost & pricing reference

Measured on Apify cloud (FREE plan, `ACTOR_COMPUTE_UNITS` = $0.20/CU):

| Run profile | CU/run | Cost/run | Cost/1k items |
|---|---|---|---|
| 60 items (~69s) | 0.0769 | ~$0.0154 | ~$0.256 |
| 100 items (~45s) | 0.0498 | ~$0.0100 | ~$0.100 |

Pricing model options (gross before Apify's 20% cut):

- Pay-per-event per 1,000 items: $0.3–$1.0. At 100 items/run, $0.3/1k gives ~141% margin, $0.5/1k ~302%, $1.0/1k ~703%.
- Flat per-run: $0.02–$0.03/run (60–140% margin at 100 items/run).

Only use sessions and accounts you own, and use the resulting public listing data in accordance with the site's terms and applicable data rules.

# Actor input Schema

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

Product keyword, for example iphone, camera or sneakers.

## `maxPages` (type: `integer`):

Maximum number of search response batches to load by scrolling.

## `maxItems` (type: `integer`):

Stop after this many deduplicated product records.

## `requestDelaySecs` (type: `number`):

Pause in seconds between result-loading scroll actions.

## `cookieHeader` (type: `string`):

Cookie request header copied from your own logged-in goofish.com browser session. Prefer QR login for local development.

## `cookieHeaders` (type: `array`):

Optional list of independently owned sessions, rotated per retry. Do not use purchased or shared accounts.

## `storageState` (type: `object`):

Alternative to Cookie headers: the JSON object produced by python -m src.login.

## `proxyConfiguration` (type: `object`):

Optional Apify proxy settings used for the browser session.

## `headless` (type: `boolean`):

Run Camoufox without a visible browser window.

## Actor input object example

```json
{
  "keyword": "iphone",
  "maxPages": 3,
  "maxItems": 100,
  "requestDelaySecs": 3,
  "headless": true
}
```

# Actor output Schema

## `listings` (type: `string`):

Public second-hand product records from the search keyword.

# 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 = {
    "keyword": "iphone"
};

// Run the Actor and wait for it to finish
const run = await client.actor("ready_ruler/xianyu-goofish-search").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 = { "keyword": "iphone" }

# Run the Actor and wait for it to finish
run = client.actor("ready_ruler/xianyu-goofish-search").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 '{
  "keyword": "iphone"
}' |
apify call ready_ruler/xianyu-goofish-search --silent --output-dataset

```

## MCP server setup

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

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/1bwtbjsMcjvBlgzcR/builds/LNbfVP7bCmnjFaf9t/openapi.json
