Skip to main content

A package for collecting TikTok videos and metadata.

Project description

Pyktok

A simple module to collect video, text, and metadata from Tiktok.

I developed Pyktok ("pick-tock") because none of the existing TikTok data collection utilities I could find worked for me. Pyktok pulls its data directly from the JSON object embedded in every Tiktok video and user page (except for save_video_comments, which uses the TikTok API). Here are its major features, most of which require the URL(s) of the content you wish to collect:

  • Download TikTok videos
  • Download video metadata
  • Download up to 20 most recent all available video comments (special thanks to @pkreissel for drafting the code for this!!!)
  • Download up to 30 most recent user video URLs
  • Download full TikTok JSON data objects (in case you want to extract data from parts of the object not included in the above functions)

This program may stop working suddenly if TikTok changes how it stores its data (see Freelon, 2018).

Installation

pip install pyktok

Requirements

Pyktok relies on the following packages:

Usage

import pyktok as pyk
    
# download a single TikTok video and one line of metadata to the file "test_data.csv"
    
pyk.save_tiktok('https://www.tiktok.com/@tiktok/video/7106594312292453675?is_copy_url=1&is_from_webapp=v1',
	        True,
                video_data.csv')
    
# download another TikTok video and add its metadata to the same file as above
    
pyk.save_tiktok('https://www.tiktok.com/@tiktok/video/7011536772089924869?is_copy_url=1&is_from_webapp=v1',
	        True,
                'video_data.csv')
    
# get a list of URLs of up to 30 of a user's most recent videos
    
tiktok_videos = pyk.get_account_video_urls('https://www.tiktok.com/@tiktok')
    
#download metadata and comment data ONLY from video URLs collected via the preceding line of code (to also download the videos, change False to True). If TikTok autobans the scraper, try changing the 0 to a higher number to increase the number of seconds between executions.
    
pyk.save_tiktok_multi(tiktok_videos,
                      False,
                      'tiktok_data.csv',
                      0)
                         
#download an individual video's JSON object
	
tt_json = pyk.get_tiktok_json('https://www.tiktok.com/@tiktok/video/7011536772089924869?is_copy_url=1&is_from_webapp=v1')

#download all available video comments (this is the default behavior, but you can change the max_comments parameter if desired)

pyk.save_video_comments('https://www.tiktok.com/@tiktok/video/7011536772089924869?is_copy_url=1&is_from_webapp=v1',
			'chair_comments.csv')
			
#download all available video comments starting with comment #3865 (if your previous download session was interrupted; you can get the comment number from the console output)

pyk.save_video_comments('https://www.tiktok.com/@tiktok/video/7011536772089924869?is_copy_url=1&is_from_webapp=v1',
			'chair_comments.csv',
			cursor_resume=3865)

TikTok's servers may not love it if you run save_tiktok_multi or save_video_comments at full speed, so I recommend increasing the sleep parameter if you get autobanned. I haven't tested this extensively so I have no idea if or when autobans start to kick in.

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

pyktok-0.0.7.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyktok-0.0.7-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyktok-0.0.7.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for pyktok-0.0.7.tar.gz
Algorithm Hash digest
SHA256 5f496465f28e730cbf841ef07ef94b3989752e86520506a55b9097d662edf6f3
MD5 79e9e811ff920bf5f95b52757979ae97
BLAKE2b-256 3787e00b85b738f89da76b899383e6915769ee31d41b23c3b3fe430aba481349

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyktok-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for pyktok-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2f09565d6796fe86e7e8bf02648fc1a3390bbad0cc58f862804a04636597d4df
MD5 04d52bdb90545418c79c199882c06a5b
BLAKE2b-256 79da45b6af93288f06b9bb14c8fa0f69a3831a6de97ba83b4356b2b82bb534ad

See more details on using hashes here.

Supported by

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