# LIHKG 連登爬蟲｜香港論壇貼文、留言、輿情、情緒一鍵匯出（免 API） (`claude_code_reviewer/lihkg-scraper`) Actor

免登入抓連登（LIHKG）香港論壇：分台主題列表、貼文全文與所有留言，含推／踩數與時間，輸出 JSON／CSV／Excel。香港輿情監測、品牌口碑、社群分析必備。

- **URL**: https://apify.com/claude\_code\_reviewer/lihkg-scraper.md
- **Developed by:** [Chad](https://apify.com/claude_code_reviewer) (community)
- **Categories:** AI, News, Social media
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 帖子列表

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## LIHKG 連登爬蟲（免 API・免登入）

抓連登（LIHKG）香港論壇最新主題列表及完整貼文留言，走 api_v2 公開 JSON 端點，輸出結構化資料。

### 輸出欄位

#### 主題列表 / 貼文主文（ThreadRow）

| 欄位名稱 | 型別 | 說明 |
|---------|------|------|
| thread_id | string | 貼文 ID |
| title | string \| null | 標題 |
| content | string \| null | 貼文主文（列表模式為 null） |
| author | string \| null | 作者暱稱 |
| category | string \| null | 分台名稱 |
| reply_count | number \| null | 回覆數 |
| like_count | number \| null | 讚數 |
| dislike_count | number \| null | 黑人問號數 |
| created_at | string \| null | 發文時間（ISO 8601） |
| thread_url | string | 貼文網址 |
| source_mode | string | 抓取模式（thread-list / thread） |
| source_query | string | 查詢條件（分台 ID 或貼文 ID） |
| scraped_at | string | 抓取時間（ISO 8601） |

#### 留言（ReplyRow）

| 欄位名稱 | 型別 | 說明 |
|---------|------|------|
| reply_id | string \| null | 留言 ID（post_id） |
| thread_id | string | 所屬貼文 ID |
| floor | number \| null | 樓層（msg_num） |
| author | string \| null | 作者暱稱 |
| content | string \| null | 留言內容（已去除 HTML 標籤） |
| like_count | number \| null | 讚數 |
| dislike_count | number \| null | 黑人問號數 |
| created_at | string \| null | 留言時間（ISO 8601） |
| scraped_at | string | 抓取時間（ISO 8601） |

### 模式說明

| 模式 | 輸入 | 輸出 | 計費 |
|-----|------|------|------|
| thread-list | catIds（分台 ID 列表） | 主題列表（ThreadRow） | $0.002/篇 |
| thread | threadIds / threadUrls | 貼文主文（$0.008/篇）＋所有留言（$0.003/則） | 依數量 |

### 輸入欄位

| 欄位 | 型別 | 預設 | 說明 |
|-----|------|------|------|
| mode | enum | thread-list | 模式：thread-list（列表）/ thread（完整貼文） |
| catIds | array | — | 分台 ID，例如 1（吹水台）、2（體育台）、5（時事台） |
| threadIds | array | — | 貼文 ID 列表 |
| threadUrls | array | — | 貼文網址，自動抽出 ID |
| bulkInput | textarea | — | 批量貼上，一行一個，自動合併到對應欄位 |
| maxItems | integer | 50 | 最多抓幾篇（列表：每分台；貼文：總篇數） |
| keywords | array | — | 標題關鍵字過濾（列表模式，留空不過濾） |
| proxyConfiguration | proxy | 不用 proxy | 大量抓取時選用 Apify Proxy |

### 輸入範例

#### 主題列表

```json
{
  "mode": "thread-list",
  "catIds": ["1", "5"],
  "maxItems": 100
}
````

#### 完整貼文及留言

```json
{
  "mode": "thread",
  "threadIds": ["4126423"],
  "maxItems": 50
}
```

#### 批量貼文網址

```json
{
  "mode": "thread",
  "threadUrls": [
    "https://lihkg.com/thread/4126423/page/1",
    "https://lihkg.com/thread/4000000/page/1"
  ],
  "maxItems": 50
}
```

### 注意事項

- 只抓公開內容，不需要帳號或 token
- 使用 api\_v2 JSON 端點（不用瀏覽器，速度快、成本低）
- 留言內容已自動去除 HTML 標籤（`<br>`、`<img>`、`<span>` 等）
- thread 模式：maxItems 限制的是**貼文篇數**，每篇留言全數抓取不受限
- 分項計費：啟動費 $0.005（一次）、列表每篇 $0.002、貼文主文每篇 $0.008、留言每則 $0.003
- 連續 5 頁無新資料時自動停止，不空轉燒費用
- LIHKG api\_v2 未來有機會加上 `X-LI-DEVICE` 標頭驗證或 challenge，並封鎖資料中心 IP。判斷方式：以 Apify cloud smoke test 結果為準（go/no-go）；若被擋，備援方案是改用 Apify residential proxy（`proxyConfiguration`），不預先過度設計

### 常見問題（FAQ）

**Q: 需要登入才能看嗎？**

A: 不需要。本 Actor 只抓公開主題列表及留言，不涉及任何需要登入的功能。

**Q: 可以同時抓多個分台嗎？**

A: 可以。在 catIds 填多個 ID，或用 bulkInput 一行一個貼上。

**Q: 留言的 HTML 要怎麼處理？**

A: 已自動處理。content 欄位輸出的是純文字，HTML 標籤已去除，HTML 實體已解碼（`&amp;` → `&`、`&lt;` → `<` 等）。

**Q: 為什麼 thread-list 模式的 content 是 null？**

A: 列表 API 不返回貼文內容，只有標題和元資料。若需要內文，改用 thread 模式。

### 免責聲明

本工具僅供學術研究及合法商業分析用途。使用者應遵守 LIHKG 服務條款及相關法規。請勿以本工具進行任何侵害他人隱私、散布虛假資訊或其他違法行為。作者不對任何濫用行為承擔責任。

***

LIHKG 爬蟲、連登、香港輿情、論壇監控、品牌聲量、香港社群數據

# Actor input Schema

## `mode` (type: `string`):

要抓什麼？選一個模式，填下面對應欄位就好。

## `catIds` (type: `array`):

分台 ID（數字），例如 1（吹水台）、2（體育台）、5（時事台）。列表模式用這個。

## `threadIds` (type: `array`):

連登貼文 ID（數字），例如 1234567。貼文模式用這個。

## `threadUrls` (type: `array`):

連登貼文完整網址，例如 https://lihkg.com/thread/1234567/page/1。會自動抽出 ID。

## `bulkInput` (type: `string`):

**一行一個**，按 Enter 換行，不要加引號或逗號。列表模式當分台 ID、貼文模式當貼文 ID/網址，執行時自動併入上面對應欄位。從 Google Sheet / Excel 複製一整欄貼進來最快。

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

列表模式：每個分台最多抓幾篇主題。貼文模式：最多抓幾篇貼文（每篇的留言不受此限）。

## `keywords` (type: `array`):

只保留標題包含任一關鍵字的主題（列表模式）。留空表示不過濾。

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

LIHKG 對一般請求友善，預設不用 proxy 即可運作。只有大量抓取遇到被擋時才建議開啟。

## Actor input object example

```json
{
  "mode": "thread-list",
  "catIds": [
    "1"
  ],
  "maxItems": 50,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

## `dataset` (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 = {
    "mode": "thread-list",
    "catIds": [
        "1"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("claude_code_reviewer/lihkg-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 = {
    "mode": "thread-list",
    "catIds": ["1"],
}

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

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

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

```

## CLI example

```bash
echo '{
  "mode": "thread-list",
  "catIds": [
    "1"
  ]
}' |
apify call claude_code_reviewer/lihkg-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=claude_code_reviewer/lihkg-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "LIHKG 連登爬蟲｜香港論壇貼文、留言、輿情、情緒一鍵匯出（免 API）",
        "description": "免登入抓連登（LIHKG）香港論壇：分台主題列表、貼文全文與所有留言，含推／踩數與時間，輸出 JSON／CSV／Excel。香港輿情監測、品牌口碑、社群分析必備。",
        "version": "1.0",
        "x-build-id": "9xrAMlCoiH2haMdDa"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/claude_code_reviewer~lihkg-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-claude_code_reviewer-lihkg-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/claude_code_reviewer~lihkg-scraper/runs": {
            "post": {
                "operationId": "runs-sync-claude_code_reviewer-lihkg-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/claude_code_reviewer~lihkg-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-claude_code_reviewer-lihkg-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "mode": {
                        "title": "🎯 模式",
                        "enum": [
                            "thread-list",
                            "thread"
                        ],
                        "type": "string",
                        "description": "要抓什麼？選一個模式，填下面對應欄位就好。",
                        "default": "thread-list"
                    },
                    "catIds": {
                        "title": "📋 分台 ID",
                        "maxItems": 50,
                        "uniqueItems": true,
                        "type": "array",
                        "description": "分台 ID（數字），例如 1（吹水台）、2（體育台）、5（時事台）。列表模式用這個。",
                        "items": {
                            "type": "string"
                        }
                    },
                    "threadIds": {
                        "title": "💬 貼文 ID",
                        "maxItems": 100,
                        "uniqueItems": true,
                        "type": "array",
                        "description": "連登貼文 ID（數字），例如 1234567。貼文模式用這個。",
                        "items": {
                            "type": "string"
                        }
                    },
                    "threadUrls": {
                        "title": "💬 貼文網址",
                        "maxItems": 100,
                        "uniqueItems": true,
                        "type": "array",
                        "description": "連登貼文完整網址，例如 https://lihkg.com/thread/1234567/page/1。會自動抽出 ID。",
                        "items": {
                            "type": "string"
                        }
                    },
                    "bulkInput": {
                        "title": "📋 批量貼上",
                        "type": "string",
                        "description": "**一行一個**，按 Enter 換行，不要加引號或逗號。列表模式當分台 ID、貼文模式當貼文 ID/網址，執行時自動併入上面對應欄位。從 Google Sheet / Excel 複製一整欄貼進來最快。"
                    },
                    "maxItems": {
                        "title": "📊 最多抓幾筆",
                        "minimum": 1,
                        "maximum": 500,
                        "type": "integer",
                        "description": "列表模式：每個分台最多抓幾篇主題。貼文模式：最多抓幾篇貼文（每篇的留言不受此限）。",
                        "default": 50
                    },
                    "keywords": {
                        "title": "🔍 關鍵字過濾",
                        "maxItems": 50,
                        "uniqueItems": true,
                        "type": "array",
                        "description": "只保留標題包含任一關鍵字的主題（列表模式）。留空表示不過濾。",
                        "items": {
                            "type": "string"
                        }
                    },
                    "proxyConfiguration": {
                        "title": "🌐 Proxy（進階，通常不用開）",
                        "type": "object",
                        "description": "LIHKG 對一般請求友善，預設不用 proxy 即可運作。只有大量抓取遇到被擋時才建議開啟。",
                        "default": {
                            "useApifyProxy": false
                        }
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
