# How do I export Douyin search results to Excel?

> Page through Douyin video search for each keyword, dedupe on the video ID, and write an .xlsx with IDs kept as text and times in Beijing time. Code, cost per 1,000 rows, and the Excel traps.

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

**Short answer: **Call okdata's Douyin video search for each keyword, follow the cursor for as many pages as you need, drop duplicate video IDs, and write the rows to an .xlsx with the IDs stored as text. Each page of about 20 videos is $0.02, so 1,000 rows cost about $1.00; refreshing the counts of chosen videos later is $0.002 each.

The request usually arrives as "can you put every Douyin video about 露营装备 and 户外电源 in a spreadsheet by Friday". Copying from the app does not scale past a screen or two, and scraped exports often open in Excel with the video IDs mangled into `7.42882E+18`. The job is three steps: search page by page, clean the rows, write a workbook that keeps the IDs intact.

## Step by step

1. **Search.** Call [Douyin video search](/apis/douyin/videos/search/) with `query` and a `sort` (`relevance`, `latest` or `most_liked`; see [what the sort options return](/answers/douyin-search-sort-params/)). Send `page.next_cursor` back as `cursor` until `page.has_more` is false or you have enough pages.
2. **Clean.** Several keywords and pages overlap, so keep one row per `id`. Turn `published_at` (UTC) into Beijing time, join `hashtags` into one cell, and keep `type` so photo posts (图文) are easy to filter.
3. **Write.** Save an .xlsx in which `id` and `author.id` are text, not numbers.

Later, when the client picks 30 videos to track, [video detail](/apis/douyin/videos/get/) refreshes their counts one by one.

## Columns worth keeping

| Column | Field | Note |
|---|---|---|
| Video ID | `id` | Write as text |
| Link | `url` | `/video/` or `/note/` |
| Type | `type` | `video` or `image` |
| Caption | `text` | Can contain line breaks and emoji |
| Posted (Beijing) | `published_at` | Converted from UTC |
| Likes, comments, shares, saves | `metrics.likes`, `metrics.comments`, `metrics.shares`, `metrics.favorites` | Plays are not public on Douyin |
| Author, author ID | `author.name`, `author.id` | `author.id` is the sec_uid |
| Hashtags | `hashtags` | Joined with spaces |

## What it costs

| Export | Calls | Cost |
|---|---|---|
| 1 keyword, 5 pages (about 100 rows) | 5 | $0.10 |
| 3 keywords, 10 pages each | 30 | $0.60 |
| Then refresh 50 chosen videos | 50 | $0.10 |

## Example

```python
import os, requests
from datetime import datetime
from zoneinfo import ZoneInfo
from openpyxl import Workbook        # pip install requests openpyxl

URL = "https://api.okdata.online/v1/douyin/videos/search"
H = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}
BJ = ZoneInfo("Asia/Shanghai")

rows = {}
for kw in ["露营装备", "户外电源"]:
    cursor = None
    for _ in range(5):
        params = {"query": kw, "sort": "most_liked", **({"cursor": cursor} if cursor else {})}
        body = requests.get(URL, headers=H, params=params, timeout=60).json()
        if body["code"] != "ok":
            raise RuntimeError(body["message"])
        for p in body["data"]["items"]:
            t = datetime.fromisoformat(p["published_at"].replace("Z", "+00:00")).astimezone(BJ)
            m = p["metrics"]
            rows.setdefault(p["id"], [kw, p["id"], p["url"], p["type"], p["text"], t.strftime("%Y-%m-%d %H:%M"),
                                      m["likes"], m["comments"], m["shares"], m["favorites"],
                                      p["author"]["name"], p["author"]["id"], " ".join(p["hashtags"] or [])])
        if not body["page"]["has_more"]:
            break
        cursor = body["page"]["next_cursor"]

wb = Workbook()
ws = wb.active
ws.append(["keyword", "video_id", "url", "type", "caption", "posted_bj", "likes", "comments",
           "shares", "saves", "author", "author_id", "hashtags"])
for r in rows.values():
    ws.append(r)                      # IDs are Python strings, so Excel keeps all 19 digits
wb.save("douyin_search.xlsx")
print(len(rows), "unique videos")
```

## Excel traps

- **Long IDs.** Excel holds 15 significant digits. A 19-digit video ID typed or imported as a number loses its last four digits for good. In .xlsx, write it as a string; in CSV, Excel will still convert it on open, so import through Data > From Text/CSV and mark the column as Text.
- **CSV encoding.** If you write CSV, use UTF-8 with a BOM (`encoding="utf-8-sig"` in Python), or Excel on Windows shows the captions as garbage.
- **Time zone.** `published_at` is UTC. Without the conversion, evening posts land on the wrong day.

## Limits

- Douyin decides how deep search goes for one keyword; pages run out. Split broad topics into narrower keywords.
- Search results carry no follower counts. Add them with [Douyin account profile](/apis/douyin/users/get/) ($0.002 per author) if the sheet needs them.
- For comments rather than videos, see [exporting Douyin comments](/answers/douyin-export-comments-sentiment/).

## Endpoints used

- [Douyin video search](https://okdata.online/apis/douyin/videos/search/) `douyin.videos.search`: $0.02 per call · about 20 videos per page
- [Douyin video detail](https://okdata.online/apis/douyin/videos/get/) `douyin.videos.get`: $0.002 per call

## More about Douyin

- [Douyin API](https://okdata.online/apis/douyin/)
- [Douyin API in Python: videos, profiles and comments (2026)](https://okdata.online/guides/douyin-api-python/)
- [How to export Douyin video comments in bulk](https://okdata.online/guides/douyin-video-comments/)
- [How to find Douyin Xingtu creators and get their rate cards](https://okdata.online/guides/douyin-xingtu-creator-rates/)
- [What is Douyin's a_bogus parameter, and do I need to generate it to get Douyin data?](https://okdata.online/answers/douyin-a-bogus-signature/)
- [How do I get Douyin, Xiaohongshu and WeChat data into Qwen?](https://okdata.online/answers/qwen-douyin-xiaohongshu-data/)
- [How can a company outside China get Douyin data in English?](https://okdata.online/answers/douyin-data-outside-china-english/)
- [Can Tencent Yuanbao read Douyin and Xiaohongshu data?](https://okdata.online/answers/yuanbao-douyin-xiaohongshu-data/)
- [What are aweme_id and modal_id in Douyin links?](https://okdata.online/answers/douyin-aweme-id-modal-id/)
- [How do I export Douyin video comments for sentiment analysis?](https://okdata.online/answers/douyin-export-comments-sentiment/)
- [How to collect Douyin comments: API, crawler or no-code (2026)](https://okdata.online/compare/douyin-comment-scraping/)
- [Douyin data APIs: official vs third-party vs open-source (2026)](https://okdata.online/compare/douyin-data-apis/)
- [Official platform APIs vs third-party data APIs (2026)](https://okdata.online/compare/official-apis-vs-data-apis/)
- [Scraping it yourself vs a per-call data API: cost, upkeep and risk](https://okdata.online/compare/scraping-vs-data-api/)

## Sources

- [Excel specifications and limits: number precision of 15 digits](https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3) (read 2026-11-12)
- [openpyxl documentation](https://openpyxl.readthedocs.io/en/stable/) (read 2026-11-12)

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

- https://juejin.cn/post/7514983928378228774
- https://learn.microsoft.com/en-us/troubleshoot/microsoft-365-apps/excel/last-digits-changed-to-zeros

Updated 2026-11-12
