Skip to main content

A simple scraper for Tiktok

Project description

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,
)
# Find by secuid
account_secuid = "MS4wLjABAAAAUgpIunuFPI8GMn_zdK8OXxV7LCY3sGClYMubx-GSpu_g75SB_Sb8nNxIKm3TytOX"
result = scraper.scrape(account_secuid, opts)
print(result.json())
# Find by username
account_name = "bancoestado_oficial"
result = scraper.scrape(account_name, opts)
print(result.json())

Output example:

{
  "name_to_show": "bancoestado_oficial",
  "id": "7158465443694724101",
  "sec_uid": "MS4wLjABAAAAUgpIunuFPI8GMn_zdK8OXxV7LCY3sGClYMubx-GSpu_g75SB_Sb8nNxIKm3TytOX",
  "followers_count": 1060,
  "following_count": 0,
  "heart_count": 2464,
  "video_count": 16,
  "friend_count": 0,
  "bio_link": "",
  "avatar": "https://p16-sign-va.tiktokcdn.com/tos-maliva-avt-0068/71fff1700b476541e48a943ce50caab5~c5_1080x1080.jpeg?lk3s=a5d48078&nonce=28069&refresh_token=878c37afe1f51de8cae6990a1ee9df9b&x-expires=1717844400&x-signature=lKabZQrNtoMJmdUW1oyfSBXcL%2Fo%3D&shp=a5d48078&shcp=81f88b70",
  "signature": "¡Somos la cuenta oficial de BancoEstado en TikTok! #Estamosporti",
  "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 posts...
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tiktok_simple_scraper-0.0.7.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

tiktok_simple_scraper-0.0.7-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file tiktok_simple_scraper-0.0.7.tar.gz.

File metadata

  • Download URL: tiktok_simple_scraper-0.0.7.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.2

File hashes

Hashes for tiktok_simple_scraper-0.0.7.tar.gz
Algorithm Hash digest
SHA256 d59ac6482a471d055634ea9b22ac911b3e434b68e725d76b499efe806dd82f64
MD5 e0a9f435af3d18bce6754bfeee21ede3
BLAKE2b-256 71365e00ef8fe7db640f762ff2c8ee20ecb7d949c22714a07ff8d49d33e63672

See more details on using hashes here.

File details

Details for the file tiktok_simple_scraper-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for tiktok_simple_scraper-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 bbf396fbb1632b2c5fd006e9d9e6f83d3ebd7e55e060f58a4a99944d34c5bb2d
MD5 4a8058602582ffca6d56d5bf1b4ee9d9
BLAKE2b-256 dca065929b3993c2fe8255e7f596e6a3511cec9d4597ec90a18a0362297ba195

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page