For AI

Answers

How do I export Douyin search results to 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 with query and a sort (relevance, latest or most_liked; see what the sort options return). 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 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

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 ($0.002 per author) if the sheet needs them.
  • For comments rather than videos, see exporting Douyin comments.

Sources

  1. Excel specifications and limits: number precision of 15 digitssupport.microsoft.com · read
  2. openpyxl documentationopenpyxl.readthedocs.io · read

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

Updated

Connect once, then just ask.

Every new key comes with $0.10 to try it. One sentence connects your agent.

Start free
Connect your AI

Paste this into your agent

Read https://okdata.online/agents.md and set up okdata for me; my key is in the OKDATA_API_KEY environment variable.

Claude Code, Cursor, Codex and other agents that can open a link set themselves up from it.

MCP serverhttps://api.okdata.online/mcp