Skip to main content

Tiktok simple scraper

Features

  • Scrapes all the posts of a tiktok account
  • Scrapes all the comments of a post

Installation

pip install tiktok_simple_scraper

Usage

You need to obtain a ms token and the "id" or "secuid" of the account. The ms token is a token that is used to authenticate the requests to the tiktok api. The "id" or "secuid" is the unique identifier of the account you want to scrape. You can obtain the ms token and the "id" or "secuid" of the account by opening tiktok and in your browser console see the requests it makes (see the network tab)

docs/ms_token_and_secuid.png

from datetime import datetime, timedelta
import os

from tiktok_simple_scraper.entities import ScraperOptions
from tiktok_simple_scraper.opts import LogCallbacks
from tiktok_simple_scraper.tiktok import TikTokAccountScraper

opts = ScraperOptions(
    most_old_date=datetime.now() - timedelta(days=3 * 30),
    max_comments_per_post=1000,
    callbacks=LogCallbacks(),
    check_account_in_storage=True,
)

ms_token = os.environ.get("MS_TOKEN")
scraper = TikTokAccountScraper(
    ms_token=ms_token,
)
account_secuid = "MS4wLjABAAAAUgpIunuFPI8GMn_zdK8OXxV7LCY3sGClYMubx-GSpu_g75SB_Sb8nNxIKm3TytOX"
result = scraper.scrape(account_secuid, opts)
print(result.json())

Output example:

{
  "name_to_show": "BancoEstado Oficial",
  "id": "MS4wLjABAAAAUgpIunuFPI8GMn_zdK8OXxV7LCY3sGClYMubx-GSpu_g75SB_Sb8nNxIKm3TytOX",
  "social_media": "TIKTOK",
  "followers_count": 0,
  "countries": [],
  "posts": [
        {
      "id": "7362193936972090629",
      "sec_id": null,
      "url": "7362193936972090629",
      "hashtags": [],
      "text": "¿Quién más así? #foryou #Bancoestado #pedropedropedropedro #trend #trending ",
      "type": "VIDEO",
      "date": "2024-04-26T11:12:36",
      "reactions": [
        {
          "type": "LIKE",
          "count": 113
        }
      ],
      "comments": [
        {
          "text": "Es viernes nuestro cuerpo lo sabe",
          "user": "elaahumada",
          "date": "2024-04-26T18:51:02",
          "url": "7362312008602256133",
          "reactions": [
            {
              "type": "LIKE",
              "count": 0
            }
          ],
          "replies": [],
          "sentiments": null,
          "user_name": "Ela Ahumada",
          "user_metadata": {
            "sec_uid": "MS4wLjABAAAALllrU5MkSPTaH2oO8ByCERShguFrTi20Z9maUWQi7Ob8ETi7XuN1fTGx_Wg3gaJr",
            "id": "239504324559560704"
          },
          "score": null
        },
        // more comments...
      ],
      "reaction_count": 113,
      "share_count": 35,
      "view_count": 12900,
      "total_comments": 0
    },
    // more posts...
  ]
}

Metadata

Release files for tiktok-simple-scraper 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tiktok-simple-scraper 0.0.9
File Size Uploaded
tiktok_simple_scraper-0.0.9.tar.gz 15.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tiktok-simple-scraper 0.0.9
File Interpreter ABI Platform
tiktok_simple_scraper-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 31.6 kB

Release files / tiktok_simple_scraper-0.0.9.tar.gz

Download URL tiktok_simple_scraper-0.0.9.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e03ba0d3ca94c9ae049a7808b8f9a03662656cbcf87686d7b77dc4f4bcb71c8b
BLAKE2b-256 checksum
How to use checksums
272cf3ef55b52159b495cdd47a5c70b521a8db84017bb4aeb9c00a6f3ff2ba0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.2

Release files / tiktok_simple_scraper-0.0.9-py3-none-any.whl

Download URL tiktok_simple_scraper-0.0.9-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
144874e5c755318a832bc23d494e77294a06ac8131c0cabee81943cbcd6a66f0
BLAKE2b-256 checksum
How to use checksums
b034dc1f909c1b78ec4d201635fb8e0b35bccd42be66d73511ad77c2327aa978
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page