> ## Content Index
> Fetch the complete content index at: https://serpapi.com/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Scrape TikTok Discover Pages
- URL: https://serpapi.com/blog/how-to-scrape-tiktok-discover-pages/
- Published: 2026-12-02T18:30:26.000Z
- Updated: 2026-12-02T18:30:26.000Z
- Description: The TikTok Discover API returns keyword-matching videos as JSON, with views, likes, comments, shares, authors, music, hashtags, and more. In this post, we'll try the API in the playground, make requests with cURL, Python, and JavaScript, and then look at pagination and customization.
- Author: Audrey Kendrick
- Tags: TikTok

TikTok Discover pages, like [TikTok Trends](https://www.tiktok.com/discover/tiktok-trends), group videos around a keyword. The top videos can vary from showing what's trending, what's popular in a niche, or which sounds and hashtags keep showing up. If you want to track those videos in your own tools, it's easiest to save them as structured data.

That's what SerpApi's [TikTok Discover API](https://serpapi.com/tiktok-discover-api) is for. You give it the keyword from a Discover page URL, and it returns the videos as JSON, with views, likes, comments, shares, authors, music, hashtags, and more.

In this post, we'll try the API in the playground, make requests with cURL, Python, and JavaScript, and then look at pagination and customization.

![](https://storage.ghost.io/c/a5/00/a5004977-0dd2-4bcd-9292-dd0e05d4c59e/content/images/2026/11/ttd_playgruobbnd.png)

## What data does the TikTok Discover API return?

The API returns a JSON object. The response is stored in the `video_results` array, and each item describes one video from the Discover page. Here are the fields you'll probably use most:

- `position`: position of the video on the page
- `id` and `link`: TikTok video ID and the link to the video
- `description`: caption of the video, including its hashtags and mentions
- `duration`: duration of the video in seconds
- `published_date`: when the video was posted (ISO 8601, UTC)
- `plays`, `likes`, `comments`, `shares`, `bookmarks`: engagement counts
- `categories`: categories TikTok assigned to the video
- `hashtags`: array of objects with `id`, `name`, and `link`
- `mentions`: array of objects with `id`, `username`, and `link`
- `author`: object with `username`, `name`, `link`, `followers`, `following`, `likes`, and `videos`
- `music`: object with `id`, `title`, `author`, `link`, and `duration`

Here's a trimmed excerpt, based on the example in the documentation:

```json
{
  "video_results": [
    {
      "position": 1,
      "id": "7696609917196651806",
      "link": "https://www.tiktok.com/@bendymoto/video/7696609917196651806",
      "duration": 12,
      "plays": 693300,
      "likes": 37100,
      "comments": 560,
      "shares": 1835,
      "bookmarks": 3844,
      "author": {
        "username": "bendymoto",
        "followers": 149200
      },
      "music": {
        "title": "original sound - P🐾",
        "duration": 12
      }
    }
  ]
}

```

A few things to keep in mind:

- Some fields only appear in some cases. For example, `sponsored` is only present on sponsored videos, `author.verified` only on verified accounts, and `music.album` only on some licensed tracks. Read them defensively in your code.
- Thumbnail links (`thumbnail`, `author.thumbnail`, `music.thumbnail`) expire after about two days, so don't store them as permanent links.
- The response also has a `serpapi_pagination` object, which we'll use in the pagination section.

You can find every field, with its type and an example, in the [TikTok Discover API documentation](https://serpapi.com/tiktok-discover-api).

## How to use the TikTok Discover API

### Try it in the playground

The fastest way to see the data is with the [SerpApi Playground](https://serpapi.com/playground?engine=tiktok%5Fdiscover&q=tiktok+trends&highlight=video%5Fresults). It opens with the TikTok Discover engine and the query `tiktok trends`, and you can change the parameters and see the result right away.

The `q` parameter is the last part of a Discover page URL. For `https://www.tiktok.com/discover/tiktok-trends`, you can use `tiktok trends` or `tiktok-trends`. Only letters, numbers, spaces, and hyphens are supported, so use `whats trending`, not `what's trending?`.

### Get your API key

To call the API from code, you need a SerpApi API key. [Register for a SerpApi account](https://serpapi.com/users/sign%5Fup), then copy your private key from your [dashboard](https://serpapi.com/dashboard). In the examples below, we use `YOUR_SERPAPI_API_KEY` as a placeholder. Never commit your real key to a repository or paste it into a public post.

For scripts and programs, keep your API key out of public source code. Instead, set an environment variable to provide your API key (listed on [your dashboard](https://serpapi.com/dashboard)) by running `export SERPAPI_KEY="YOUR_API_KEY"` for Mac and `$env:SERPAPI_KEY="YOUR_API_KEY"` for Windows. If a key is accidentally exposed, you can regenerate it from the SerpApi dashboard.

### Make a GET request

The API endpoint is `https://serpapi.com/search?engine=tiktok_discover`. The required parameters are `engine`, `q`, and `api_key`. JSON is the default output, so this request returns JSON:

```
https://serpapi.com/search?engine=tiktok_discover&q=tiktok+trends&gl=us&api_key=YOUR_SERPAPI_API_KEY

```

`gl` is optional. It's a two-letter country code, and it defaults to `us`.

### Request Markdown output

If you want a more readable, token-efficient version of the results, for example to pass to an LLM or AI agent, add `output=md`:

```
https://serpapi.com/search?engine=tiktok_discover&q=tiktok+trends&gl=us&output=md&api_key=YOUR_SERPAPI_API_KEY

```

The documentation also lists the `/search.md` endpoint and the `Accept: text/markdown` request header as other ways to get Markdown. Read more on the [Markdown output page](https://serpapi.com/markdown-output).

Markdown is a curated view of the results, made for reading. When you need exact field access in code, like the examples below, use the JSON output.

### cURL

This cURL request is equivalent to the JSON GET request above. (The documentation doesn't include a cURL example, so this one is built from the documented endpoint and parameters.)

```bash
curl --get "https://serpapi.com/search" \
  --data-urlencode "engine=tiktok_discover" \
  --data-urlencode "q=tiktok trends" \
  --data-urlencode "gl=us" \
  --data-urlencode "api_key=$SERPAPI_API_KEY"

```

`--get` with `--data-urlencode` takes care of encoding the space in `tiktok trends` for you.

![](https://storage.ghost.io/c/a5/00/a5004977-0dd2-4bcd-9292-dd0e05d4c59e/content/images/2026/12/ttd_curl.png)

The TikTok Discover cURL call result

### Python

SerpApi has an official Python library. Check out the [Python integration page](https://serpapi.com/integrations/python) for details. Install it with:

```bash
pip install serpapi

```

Then create a file named `main.py`:

```python
import os
import serpapi

client = serpapi.Client(api_key=os.environ["SERPAPI_API_KEY"], timeout=60)

results = client.search({
    "engine": "tiktok_discover",
    "q": "tiktok trends",
    "gl": "us",
})

if "error" in results:
    raise SystemExit("The search failed. Check your API key and parameters.")

videos = results.get("video_results", [])
if not videos:
    print("No videos found.")

for video in videos[:5]:
    author = video.get("author", {})
    print(f'#{video["position"]} @{author.get("username")} - {video.get("plays")} plays - {video["link"]}')

```

Run it with:

```bash
python main.py

```

Results should look like:

![](https://storage.ghost.io/c/a5/00/a5004977-0dd2-4bcd-9292-dd0e05d4c59e/content/images/2026/12/ttd_py.png)

The TikTok Discover API Python Results

Here's what the script does:

- It reads your key from `SERPAPI_API_KEY`, so the key stays out of your code. If the variable isn't set, the script stops with an error.
- It sends one search for the keyword `tiktok trends` and gets the results back as a dictionary-like object, so there's no JSON to decode yourself.
- If the response contains an `error`, it stops. If the request worked but `video_results` is empty, it prints "No videos found." These are two different situations.
- It prints the position, author username, play count, and link of the first five videos. We use `.get()` for fields that might be missing.

Want to keep the results in a spreadsheet? A list of videos fits naturally into rows. This version uses the standard `csv` module and flattens the nested fields, taking `author.username` and `music.title` and joining the hashtag names with semicolons. Add it to the end of `main.py`:

```python
import csv

with open("tiktok_videos.csv", "w", newline="", encoding="utf-8") as file:
    writer = csv.writer(file)
    writer.writerow(["position", "link", "plays", "likes", "comments", "shares", "author", "music", "hashtags"])
    for video in videos:
        writer.writerow([
            video["position"],
            video["link"],
            video.get("plays"),
            video.get("likes"),
            video.get("comments"),
            video.get("shares"),
            video.get("author", {}).get("username"),
            video.get("music", {}).get("title"),
            ";".join(tag["name"] for tag in video.get("hashtags", [])),
        ])

```

*Optional:* for production scripts, you may want to add retries and handle the library's HTTP and timeout exceptions. The example above is kept short so it's easy to start with.

### JavaScript

SerpApi also has an official [JavaScript library](https://github.com/serpapi/serpapi-javascript/). Install it with:

```bash
npm install serpapi

```

Create a file named `main.js`:

```javascript
async function main() {
  const { getJson } = await import("serpapi");

  const apiKey = process.env.SERPAPI_API_KEY;
  if (!apiKey) {
    console.error("Set the SERPAPI_API_KEY environment variable first.");
    process.exit(1);
  }

  try {
    const results = await getJson({
      engine: "tiktok_discover",
      q: "tiktok trends",
      gl: "us",
      api_key: apiKey,
    });

    if (results.error) {
      console.error("The search failed. Check your API key and parameters.");
      process.exit(1);
    }

    const videos = results.video_results ?? [];
    if (videos.length === 0) {
      console.log("No videos found.");
      return;
    }

    for (const video of videos.slice(0, 5)) {
      console.log(
        `#${video.position} @${video.author?.username} - ${video.plays} plays - ${video.link}`
      );
    }
  } catch (error) {
    console.error("The request failed. Check your network connection and API key.");
    process.exit(1);
  }
}

main();

```

Run it with:

```bash
node main.js

```

The results should look like:

![](https://storage.ghost.io/c/a5/00/a5004977-0dd2-4bcd-9292-dd0e05d4c59e/content/images/2026/12/ttd_js.png)

The TikTok Discover JS Results

### Other languages and no-code tools

SerpApi has libraries for other languages too. You can find them on the [integrations page](https://serpapi.com/integrations). If you prefer no-code automation, SerpApi announced a [Make app](https://serpapi.com/blog/announcing-serpapis-make-app/) and a [verified n8n node](https://serpapi.com/blog/boost-your-n8n-workflows-with-serpapis-verified-node/). 

## Paginate through more videos

A TikTok Discover page holds about 100 videos in total. There are two ways to get them:

1. **Ask for them all at once.** The `num` parameter sets the maximum number of results, from `1` to `100`. The default is `16`, so `num=100` returns the whole page in one request.
2. **Go page by page.** The `start` parameter is the result offset. With the default `num` of 16, `start=0` is the first page, `start=16` is the second, `start=32` is the third, and so on.

There's one catch with page-by-page requests. TikTok orders the videos differently for each session, so if you only change `start`, the next page can repeat videos from the previous one. To avoid that, pass the `session_token` from the first response. It's returned in `serpapi_pagination.session_token`. The `previous` and `next` links in `serpapi_pagination` already include it, and `next` is only present when TikTok has more videos for the keyword.

Here's a short extension of the Python script. It reuses the same client, collects up to three pages, and stops when there's no `next` link:

```python
params = {"engine": "tiktok_discover", "q": "tiktok trends", "start": 0}
all_videos = []

for _ in range(3):
    page = client.search(params)
    if "error" in page:
        raise SystemExit("The search failed. Check your API key and parameters.")

    all_videos.extend(page.get("video_results", []))

    pagination = page.get("serpapi_pagination", {})
    if "next" not in pagination:
        break

    params["start"] += 16
    params["session_token"] = pagination["session_token"]

print(f"Collected {len(all_videos)} videos")

```

This loop assumes the default page size of 16\. If you change `num`, follow the `next` link from `serpapi_pagination` instead of guessing the offset.

## Customize your requests

The documentation lists a few optional parameters that are handy for this API:

- `**q**`: change the keyword to explore other Discover pages, such as `whats trending`.
- `**gl**`: pick the country, using a two-letter code like `us` (default), `uk`, or `fr`. See the [Google countries page](https://serpapi.com/google-countries) for the full list.
- **`num`**: control how many videos come back (1 to 100).
- `**no_cache**`: set to `true` to force a fresh fetch. By default, SerpApi can serve a cached result if the query and parameters are exactly the same. The cache expires after 1 hour, and cached searches don't count toward your monthly searches.
- **`json_restrictor`**: return only the fields you need to reduce the payload size. See the [JSON Restrictor documentation](https://serpapi.com/json-restrictor).

For example, to get the top 50 videos from the French Discover page, change the parameters in your Python script:

```python
results = client.search({
    "engine": "tiktok_discover",
    "q": "tiktok trends",
    "gl": "fr",
    "num": 50,
})

```

The documentation doesn't list request filters like "only videos from this category." The `categories` and `hashtags` of each video come back as response data, so if you want to narrow things down, filter the `video_results` in your own code.

## Conclusion

In this post, we looked at SerpApi's TikTok Discover API, including what's in `video_results`, how to make requests in the playground, with GET, cURL, Python, and JavaScript, how to get Markdown output, and how to paginate with `start` and `session_token`. From here, you could track how the videos on a keyword change over time, compare countries with `gl`, or send the Markdown output straight to an LLM.

For all the parameters and fields, see the [TikTok Discover API documentation](https://serpapi.com/tiktok-discover-api). SerpApi also lists a separate [TikTok Shop API](https://serpapi.com/tiktok-shop-api) in its documentation, if you're interested in TikTok from a different angle.

If you would like to learn more about scraping short form video data on other platforms, like YouTube Shorts, check out this article:

[How to Scrape YouTube Shorts videos resultsYouTube is one of the most popular online video platforms. Videos are published on different topics, such as music, entertainment, education, news, sports, and more. YouTube also has a feature called shorts, vertical videos, 60 seconds long and can be created and watched on mobile devices. YouTube shorts are similar![](https://storage.ghost.io/c/a5/00/a5004977-0dd2-4bcd-9292-dd0e05d4c59e/content/images/icon/serpapi-favicon-16c053f8-179f-43c6-834a-721cd46cac7a.png)SerpApiAndy L![](https://storage.ghost.io/c/a5/00/a5004977-0dd2-4bcd-9292-dd0e05d4c59e/content/images/thumbnail/Screen-Shot-2022-05-30-at-22.17.37-152f237d-43f6-45b2-86bd-caff94ed580f.png)](https://serpapi.com/blog/how-to-scrape-youtube-shorts-videos-results/)