# Baidu Tieba Scraper 百度贴吧 - Threads, Replies & Search (`xiaoliang527/tieba-posts-comments-scraper`) Actor

Scrape Baidu Tieba (百度贴吧): threads of any forum (吧), full replies (楼层), sub-replies (楼中楼) and site-wide keyword search. No login or cookies. $2 per 1,000 results.

- **URL**: https://apify.com/xiaoliang527/tieba-posts-comments-scraper.md
- **Developed by:** [xiao liang](https://apify.com/xiaoliang527) (community)
- **Categories:** Social media, Lead generation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$2.00 / 1,000 results

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

## Baidu Tieba Scraper 百度贴吧 - Forum Threads, Replies, Sub-replies & Search

Scrape **Baidu Tieba (百度贴吧)**, China's largest forum platform, and get clean JSON. One Actor covers everything:

- **Forum threads (吧内帖子)**: the thread list of any forum (吧), sorted by latest reply or newest, optionally only featured (精品) threads, plus forum stats (members, posts, threads).
- **Replies (楼层)**: every floor of a thread with full text, images, videos, author and like counts.
- **Sub-replies (楼中楼)**: the nested replies under each floor.
- **Keyword search (全站搜索)**: find threads across all of Tieba by keyword, newest first.

Key points:

- **No login, no cookies.** Only public data is collected, and your account is never involved.
- **$2 per 1,000 results**, one flat price for threads, replies and sub-replies.
- **Fails loudly.** If Baidu blocks the requests, the run fails with a clear message. It never silently returns an empty dataset.

### Input

| Field | Description |
|---|---|
| `mode` | `forum`, `thread` or `search` |
| `forumNames` | (forum) Forum names, with or without 吧, e.g. `["电动车", "李毅吧"]` |
| `threadUrlsOrIds` | (thread) `https://tieba.baidu.com/p/11055481323` or `11055481323`. Replies are always included in this mode |
| `searchKeywords` | (search) Keywords, e.g. `["电动车 电池"]` |
| `maxThreadsPerSource` | Threads per forum or keyword (default 50) |
| `onlyGood` | (forum) Only featured threads (精品贴) |
| `sortBy` | (forum) `reply` (latest reply) or `create` (newest thread) |
| `includeReplies`, `maxRepliesPerThread` | Add the replies (floors) of each thread (default 100 per thread) |
| `includeSubReplies`, `maxSubRepliesPerFloor` | Add the sub-replies under each floor (default 20 per floor) |
| `requestDelaySecs` | Pause between requests, minimum 1.5 s |

```json
{
  "mode": "forum",
  "forumNames": ["电动车"],
  "maxThreadsPerSource": 100,
  "sortBy": "create",
  "includeReplies": true,
  "maxRepliesPerThread": 50
}
```

### Output

Every dataset item has a `type`: `forum`, `thread`, `reply`, `sub_reply` or `error`. They all share these fields: `platform`, `tid`, `pid`, `forumName`, `forumId`, `title`, `text` (HTML stripped, emoticons as `[name]`), `media` (images, videos and links), `authorId`, `authorName`, `authorNickname`, `authorPortrait`, `createdAt` (ISO 8601, UTC), `url` and `scrapedAt`.

```json
{
  "platform": "tieba",
  "type": "thread",
  "tid": 10200085026,
  "forumName": "电动车",
  "forumId": 2767,
  "title": "我好像被骗了，还有没被骗的",
  "text": "现在买完了qq不理人，报案有用吗",
  "media": [{"type": "image", "url": "http://tiebapic.baidu.com/forum/pic/item/7c11b05....jpg"}],
  "authorId": 879898799,
  "authorName": "墨轩七月",
  "authorNickname": "墨轩七月",
  "createdAt": "2025-11-09T11:03:57+00:00",
  "url": "https://tieba.baidu.com/p/10200085026",
  "replyCount": 51,
  "agreeCount": 47,
  "lastReplyAt": "2026-08-05T01:37:42+00:00",
  "isTop": true
}
```

```json
{"type": "reply", "tid": 10200085026, "pid": 152837796035, "floor": 2, "text": "叫巅峰车行的，还在吧里发帖", "authorNickname": "墨轩七月", "agreeCount": 0, "disagreeCount": 0, "subReplyCount": 0, "createdAt": "2025-11-09T11:04:57+00:00"}
```

```json
{"type": "sub_reply", "tid": 10200085026, "pid": 152837843626, "parentPid": 152837830934, "text": "是啊蠢了", "authorNickname": "墨轩七月", "createdAt": "2025-11-09T11:18:14+00:00"}
```

```json
{"type": "forum", "forumName": "电动车", "forumId": 2767, "memberCount": 359231, "postCount": 3243414, "threadCount": 127018, "category": "生活/交通工具"}
```

Field details:

- **Thread** items also have `replyCount`, `agreeCount`, `lastReplyAt`, `isTop`, `isGood` and `abstract`. In forum mode `text` is Tieba's short abstract. When `includeReplies` is on, `text` is replaced by the full first post.
- **Reply** items also have `floor`, `agreeCount`, `disagreeCount` and `subReplyCount`. Floor 1 (the opening post) is inside the thread item, so replies start at floor 2.
- **Sub-reply** items also have `parentPid`.

### Use cases

- **Consumer and brand research in China**: what real users say about a product, brand, car or EV model, with reply and like counts.
- **Sentiment and topic analysis**: full reply threads with nested discussions, ready for an LLM or NLP pipeline.
- **Lead generation and community monitoring**: track new threads in niche forums (second-hand trading, local city forums, product forums).

### Use it from code, n8n or an AI agent

```python
from apify_client import ApifyClient

client = ApifyClient("<YOUR_APIFY_TOKEN>")
run = client.actor("xiaoliang527/tieba-posts-comments-scraper").call(run_input={
    "mode": "search", "searchKeywords": ["电动车 电池"], "maxThreadsPerSource": 40})
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    if item["type"] == "thread":
        print(item["forumName"], item["title"], item["replyCount"])
```

**MCP (Claude, Cursor):** `https://mcp.apify.com?tools=xiaoliang527/tieba-posts-comments-scraper` with your Apify token as Bearer header.

### Pricing

| Event | Price |
|---|---|
| Result (thread, reply or sub-reply) | $0.002 ($2 / 1,000) |
| Forum info item | free |
| Errors (forum not found, deleted thread, invalid URL) | free |

Set a maximum cost per run in the run options and the Actor stops cleanly when it is reached.

### Limits

- Only public content. Deleted, hidden or login-only content is not available.
- Search returns about 20 threads per page, newest first. Very deep result pages may not be available.
- In search results some authors have only a nickname (`authorName` is `null`).
- Sub-replies need one extra request for each floor that has many of them, so runs with `includeSubReplies` are slower.
- Requests are sent one at a time with at least 1.5 s between them, to be gentle with Tieba. About 30 threads, 30 replies or 20 search results come back per request.
- Very large forums report up to 1,000 pages of threads. Use `maxThreadsPerSource` to limit how deep the Actor goes.
- If Baidu starts showing its security check (百度安全验证), the run stops with an error instead of returning partial or empty data silently. Try again later.

# Actor input Schema

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

What to scrape: threads of forums, specific threads, or a site-wide keyword search.

## `forumNames` (type: `array`):

Tieba forum names, with or without the trailing 吧, e.g. 电动车 or 李毅吧.

## `threadUrlsOrIds` (type: `array`):

e.g. https://tieba.baidu.com/p/11055481323 or 11055481323. Replies are always included in this mode.

## `searchKeywords` (type: `array`):

Search all of Tieba for threads matching each keyword (newest first).

## `maxThreadsPerSource` (type: `integer`):

How many threads to return for each forum or keyword (30 per page for forums, 20 for search). Pinned threads count too.

## `onlyGood` (type: `boolean`):

Forum mode: return only the forum's featured (精品) threads.

## `sortBy` (type: `string`):

Forum mode: order of the thread list.

## `includeReplies` (type: `boolean`):

Also fetch the replies (floors) of each thread. The thread text is then upgraded from the short abstract to the full first post.

## `maxRepliesPerThread` (type: `integer`):

Replies (floors 2, 3, ...) to return per thread, oldest first. Sub-replies are not counted here.

## `includeSubReplies` (type: `boolean`):

Also fetch the replies nested under each floor. Needs one extra request per floor that has many of them, so runs get slower.

## `maxSubRepliesPerFloor` (type: `integer`):

Sub-replies to return under each floor.

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

Pause between requests to Tieba (minimum 1.5). Raise it if you see blocking errors.

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

Usually not needed.

## Actor input object example

```json
{
  "mode": "forum",
  "forumNames": [
    "电动车"
  ],
  "maxThreadsPerSource": 50,
  "onlyGood": false,
  "sortBy": "reply",
  "includeReplies": false,
  "maxRepliesPerThread": 100,
  "includeSubReplies": false,
  "maxSubRepliesPerFloor": 20,
  "requestDelaySecs": 1.5,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

## `items` (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 = {
    "forumNames": [
        "电动车"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("xiaoliang527/tieba-posts-comments-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 = { "forumNames": ["电动车"] }

# Run the Actor and wait for it to finish
run = client.actor("xiaoliang527/tieba-posts-comments-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 '{
  "forumNames": [
    "电动车"
  ]
}' |
apify call xiaoliang527/tieba-posts-comments-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,xiaoliang527/tieba-posts-comments-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/p2O3c6lUeReASTsuR/builds/Wb1txb9GukbUqiX4E/openapi.json
