npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tiktok-scraper-music

v1.0.6

Published

TikTok Scraper & Downloader. Scrape information from User, Trending and HashTag pages and download video posts

Downloads

1

Readme

TikTok Scraper & Downloader

Scrape and download useful information from TikTok.

No login or password are required.

This is not an official API support and etc. This is just a scraper that is using TikTok Web API to scrape media.



Features

  • Scrape video posts from username, hashtag, trends, or music-id
  • Download and save media to a ZIP archive
  • Create JSON/CSV files with a post information

Note:

  • If you need to download all video posts then set {number} to 0

Posts - JSON/CSV output:

    id: '6748606789551410438',
    text:'TEXT',
    createTime: '1571282470',
    authorId: '123123',
    musicId: '123123',
    videoUrl: 'VIDEO_URL',
    diggCount: 485,
    shareCount: 1,
    commentCount: 24 

Demo

Possible errors

  • Unknown. Report them if you will hit any

Installation

tiktok-scraper requires Node.js v10+ to run.

Install from NPM

$ npm i -g tiktok-scraper

Install from YARN

$ yarn global add tiktok-scraper

USAGE

In Terminal

$ tiktok-scraper --help

Usage: tiktok-scraper <command> [options]

Commands:
  tiktok-scraper user [id]     Scrape videos from username. Enter only username
  tiktok-scraper hashtag [id]  Scrape videos from hashtag. Enter hashtag without #
  tiktok-scraper trend         Scrape posts from current trends
  tiktok-scraper music [id]    Scrape posts from a music id number

Options:
  --help, -h              help                                         [boolean]
  --version               Show version number                          [boolean]
  --number, -n            Number of posts to scrape. If you will set 0 then all
                          posts will be scraped                    [default: 20]
  --proxy, -p             Set proxy                                [default: ""]
  --timeout               If you will receive 'rate limit' error , you can try
                          to set timeout. Timeout is in mls: 1000 mls = 1 second
                                                                    [default: 0]
  --download, -d          Download and archive all scraped videos to a ZIP file
                                                      [boolean] [default: false]
  --filepath              Directory to save all output files.
                [default: "/Users/jackass/Documents/lang/NodeJs/tiktok-scraper"]
  --filetype, --type, -t  Type of output file where post information will be
                          saved. 'all' - save information about all posts to a
                          'json' and 'csv'
                                [choices: "csv", "json", "all"] [default: "csv"]

Examples:
  tiktok-scraper user USERNAME -d -n 100
  tiktok-scraper hashtag HASHTAG_NAME -d -n 100
  tiktok-scraper trend -d -n 100
  tiktok-scraper music MUSICID -n 100

Example 1: Scrape 300 video posts from user {USERNAME}. Save post info in to a CSV file (by default)

$ tiktok-scraper user USERNAME -n 300

Output:
CSV path: /{CURRENT_PATH}/user_1552945544582.csv

Example 2: Scrape 100 posts from hashtag {HASHTAG_NAME}, download and save them to a ZIP archive. Save post info in to a JSON and CSV files (--filetype all)

$ tiktok-scraper hashtag HASHTAG_NAME -n 100 -d -t all

Output:
ZIP path: /{CURRENT_PATH}/hashtag_1552945659138.zip
JSON path: /{CURRENT_PATH}/hashtag_1552945659138.json
CSV path: /{CURRENT_PATH}/hashtag_1552945659138.csv

Example 3: Scrape 50 posts from trends section, download them to a ZIP and save info to a csv file

$ tiktok-scraper trend -n 50 -d -t csv


Output:
ZIP path: /{CURRENT_PATH}/trend_1552945659138.zip
CSV path: /{CURRENT_PATH}/tend_1552945659138.csv

Example 4: Scrape 100 posts from a particular music ID (numberical ID from TikTok URL)

$ tiktok-scraper music MUSICID -n 100

Output:
ZIP path: /{CURRENT_PATH}/music_1552945659138.zip
CSV path: /{CURRENT_PATH}/music_1552945659138.csv

To make it look better, when downloading posts the progress will be shown in terminal

Downloading 6750670497744309509 [==============================] 100%
Downloading 6749962264020782342 [==============================] 100%
Downloading 6749433991113264390 [==============================] 100%
Downloading 6750671571968429318 [==============================] 100%
Downloading 6750668198011505926 [==============================] 100%
Downloading 6748611221903117574 [==============================] 100%
Downloading 6748606789551410438 [==============================] 100%
Downloading 6748139550251535621 [==============================] 100%
Downloading 6748616311166799110 [==============================] 100%
Downloading 6748048372625689861 [==============================] 100%

Module

Promise

const TikTokScraper = require('tiktok-scraper');


// User feed by username
(async () => {
    try{
        let posts = await TikTokScraper.user({USERNAME},  { number: 100 });
        console.log(posts)
    } catch(error){
        console.log(error)
    }
})()

// User feed by user id
// Some TikTok user id's are larger then MAX_SAFE_INTEGER, you need to pass user id as a string
(async () => {
    try{
        let posts = await TikTokScraper.user({USER_ID}, { number: 100, by_user_id: true });
        console.log(posts)
    } catch(error){
        console.log(error)
    }
})()

// Trend
(async () => {
    try{
        let posts = await TikTokScraper.trend("", { number: 100 });
        console.log(posts)
    } catch(error){
        console.log(error)
    }
})()

// Hashtag
(async () => {
    try{
        let posts = await TikTokScraper.hashtag({HASHTAG}, { number: 100 });
        console.log(posts)
    } catch(error){
        console.log(error)
    }
})()

Promise will return current result

{
    collector:[ARRAY_OF_DATA]
    //If {filetype} and {download} options are enbabled then:
    zip: '/{CURRENT_PATH}/user_1552963581094.zip',
    json: '/{CURRENT_PATH}/user_1552963581094.json',
    csv: '/{CURRENT_PATH}/user_1552963581094.csv' 
}

Event

const TikTokScraper = require('tiktok-scraper');
let options = {
    count: 100,
    event: true, // Enable event emitter, you won't be able to use promises
};

let posts = TikTokScraper.user({USERNAME}, options);

posts.on('data', (json) => {
  //data in JSON format
})

posts.on('done', () => {
  //completed
})
posts.on('error', (error) => {
  //error message
})

Functions

.user(id, options) //Scrape posts from a specific user
.hashtag(id, options) //Scrape posts from hashtag section
.trend('', options) // Scrape posts from a trends section

Options

let options = {
    // Number of posts to scrape: {int default: 20}
    number: 50,
    
    // Set proxy, example: 127.0.0.1:8080: {string default: ''}
    proxy: '',

    // Enable or Disable event emitter. If true then you can accept data through events: {boolean default: false}
    event: false,

    // Timeout between requests. If 'rate limit' error received then this option can be useful: {int default: 0}
    timeout: 0,
    
    // Set to {true} to search by user id: {boolean default: false}
    by_user_id: false,
    
    // Download posts or not. If true ZIP archive in {filepath} will be created: {boolean default: false}
    download: false,

    // How many post should be downloaded asynchronously. Only if {download:true}: {int default: 5}
    asyncDownload: 5,

    // File path where all files will be saved: {string default: 'CURRENT_DIR'}
    filepath: `CURRENT_DIR`,

    // Output with information can be saved to a CSV or JSON files: {string default: 'na'}
    // 'csv' to save in csv
    // 'json' to save in json
    // 'all' to save in json and csv
    // 'na' to skip this step
    filetype: `na`,
};


License

MIT

Free Software