# How do I export Weibo search results to Excel?

> Turn a Weibo keyword search into an .xlsx file: page through results, keep 16-digit post IDs as text, convert times to Beijing, add author profiles. Cost, code and pitfalls.

Canonical page: https://okdata.online/answers/weibo-search-export-excel/

**Short answer: **Page through Weibo post search for your keyword and write each post as a row with openpyxl, keeping post and user IDs as text and times in Beijing time. Each page holds about 10 posts for $0.002, so 30 pages (around 300 posts) cost $0.06; adding profiles for 120 unique authors with Weibo account profile brings it to $0.30.

The request is always the same: "send me what people are saying on Weibo about 露营 装备, in Excel". The search part is easy. The spreadsheet part is where exports go wrong: post IDs lose their last digit, Chinese turns into garbage, and every time is eight hours off. This page does the search with one endpoint and writes an .xlsx that opens cleanly.

## The columns you get

From [Weibo post search](/apis/weibo/posts/search/) with `view=full`:

| Column | Field |
|---|---|
| Post ID (mid) | `id` |
| Link | `url`, in the form weibo.com/uid/bid |
| Author UID, name, followers | `author.id`, `author.name`, `author.followers` |
| Published | `published_at` (UTC; convert to Beijing) |
| Text | `text` |
| Reposts, comments, likes | `metrics.reposts`, `metrics.comments`, `metrics.likes` |
| Video plays | `metrics.views`, for video posts only |
| IP region shown on the post | `ext.region` |
| Text cut short in search | `ext.is_long_text` |

Shares and favorites are not public on Weibo; they come back null with `platform` in `meta.unavailable`. For more on each author, such as verification text and post count, look up the unique `author.id` values with [Weibo account profile](/apis/weibo/users/get/).

## Three Excel traps

1. **Long IDs.** A Weibo post ID has 16 digits, and Excel keeps only 15 significant digits of a number, so `5249013377610245` becomes `5249013377610240`, displayed as `5.24901E+15`. Users of open-source Weibo scrapers report exactly this. Write IDs as text, which openpyxl does when you pass a string.
2. **Encoding.** A CSV opened by double-click can show garbled Chinese, another regular complaint in scraper issue trackers. Writing .xlsx avoids the question entirely.
3. **Time zone.** `published_at` is UTC. Convert to Beijing time (UTC+8) before writing, and say so in the header.

## Cost

| Export | Calls | Cost |
|---|---|---|
| One page, about 10 posts | 1 | $0.002 |
| 30 pages, about 300 posts | 30 | $0.06 |
| The same plus 120 author profiles | 150 | $0.30 |

## Example

Install `requests` and `openpyxl`, set your key, then:

```python
import os, requests
from datetime import datetime, timezone, timedelta
from openpyxl import Workbook

API = "https://api.okdata.online"
H = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}
BJ = timezone(timedelta(hours=8))
QUERY, MAX_PAGES = "露营 装备", 30

def call(path, **params):
    body = requests.get(API + path, headers=H, params=params, timeout=60).json()
    if body["code"] != "ok":
        raise RuntimeError(f'{body["code"]}: {body["message"]}')
    return body

wb = Workbook()
ws = wb.active
ws.title = "posts"
ws.append(["mid", "link", "uid", "author", "followers", "published (Beijing)", "text",
           "reposts", "comments", "likes", "plays", "IP region", "text cut"])
seen, cursor = set(), None
for _ in range(MAX_PAGES):
    params = {"query": QUERY, "sort": "latest", "view": "full"}
    if cursor:
        params["cursor"] = cursor
    body = call("/v1/weibo/posts/search", **params)
    for p in body["data"]["items"]:
        if p["id"] in seen:
            continue
        seen.add(p["id"])
        when = datetime.fromisoformat(p["published_at"].replace("Z", "+00:00")).astimezone(BJ)
        m, a = p["metrics"], p["author"]
        ws.append([p["id"], p["url"], a["id"], a["name"], a["followers"], when.replace(tzinfo=None),
                   p["text"], m["reposts"], m["comments"], m["likes"], m["views"],
                   p["ext"].get("region"), p["ext"].get("is_long_text")])
    if not body["page"]["has_more"]:
        break
    cursor = body["page"]["next_cursor"]

wb.save("weibo-camping.xlsx")  # IDs were written as strings, so all 16 digits survive
```

To add an "authors" sheet, call `/v1/weibo/users/get` with `id=<uid>` and `view=full` once per unique `author.id` and write `name`, `followers`, `posts`, `verified`, `ext.verified_reason` and `ext.ip_location`.

## Limits

- Weibo search returns what Weibo ranks for the keyword, not every post ever made. For wider coverage, run `sort=hot` and `sort=latest` and merge by `id`, as in [collecting Weibo posts for public-opinion analysis](/answers/weibo-public-opinion-dataset/).
- Posts marked `ext.is_long_text` arrive with the shortened text Weibo shows in search. The catalog has no Weibo post detail endpoint to fetch the full text.
- No Weibo login or cookie is involved; see [searching Weibo without a cookie](/answers/weibo-search-without-cookie/). Only public posts are returned.

## Endpoints used

- [Weibo post search](https://okdata.online/apis/weibo/posts/search/) `weibo.posts.search`: $0.002 per call · about 10 posts per page
- [Weibo account profile](https://okdata.online/apis/weibo/users/get/) `weibo.users.get`: $0.002 per call

## More about Weibo

- [Weibo API](https://okdata.online/apis/weibo/)
- [Weibo API in Python: search, profiles and hot search (2026)](https://okdata.online/guides/weibo-api-python/)
- [How do I get IP location (IP属地) data from Weibo posts and Bilibili comments?](https://okdata.online/answers/weibo-bilibili-ip-location-data/)
- [How do I find Weibo bloggers (KOLs) in a niche?](https://okdata.online/answers/weibo-find-kols-in-niche/)
- [Does Weibo still have an open API for reading posts in 2026?](https://okdata.online/answers/weibo-official-api-2026/)
- [How do I collect Weibo posts on a topic for public-opinion analysis?](https://okdata.online/answers/weibo-public-opinion-dataset/)
- [What are uid, mid and bid on Weibo?](https://okdata.online/answers/weibo-uid-mid-bid/)
- [Profile API](https://okdata.online/roles/accounts-get/)
- [Post search API](https://okdata.online/roles/posts-search/)
- [Weibo hot search: today’s list](https://okdata.online/tools/hot-search/weibo/)

## Sources

- [Microsoft Support: Keeping leading zeros and large numbers in Excel](https://support.microsoft.com/en-us/excel/keeping-leading-zeros-and-large-numbers) (read 2026-11-12)
- [openpyxl documentation](https://openpyxl.readthedocs.io/en/stable/) (read 2026-11-12)
- [dataabc/weibo-search issue 208: post ids shown as 4.75E+15 in Excel](https://github.com/dataabc/weibo-search/issues/208) (read 2026-11-12)
- [dataabc/weiboSpider issue 565: garbled text when writing CSV](https://github.com/dataabc/weiboSpider/issues/565) (read 2026-11-12)

Where people asked this (read 2026-11-12): 

- https://github.com/dataabc/weibo-search/issues/208
- https://github.com/dataabc/weiboSpider/issues/565
- https://www.v2ex.com/t/389043

Updated 2026-11-12
