3.6 KiB
TikTok hashtag analysis toolset
The tool helps to download posts and videos from tiktok for a given set of hashtags. It uses tiktok-scraper (https://github.com/drawrowfly/tiktok-scraper) to download the posts and videos.
Pre-requisites
- Make sure you have python 3.8 or later version installed.
- Download and install TikTok scraper: https://github.com/drawrowfly/tiktok-scraper
Options for running run_downloader.py
python3 run_downloader.py -h
Data organization
data folder contains all the downloaded data as shown in the pic above.
- the
logfolder contains log.json which records the total number of downloaded posts and videos for the hashtags against the time stamp of when the script is run. - the
idsfolder contains two filespost_ids.jsonandvideo_ids.jsonthat records the ids of the downloaded posts and videos for each hashtag. - Each hashtag has a folder with two subfolders
postsandvideosthat store posts and videos respectively. The posts are stored in thedata.jsonfile in thepostsfolder, and videos are stored as the.mp4files in thevideosfolder.
Post download
Run the run_downloader.py with the following option:
python3 run_downloader.py --h london paris newyork -p
- The --h option allows to type in hashtag list in the commandline.
- -p option specifies the download posts option.
Video download
python3 run_downloader.py --h london -v
- --h option allows to type in the list of hashtags as command line argument.
- -v option is for downloading the videos The above code download all the trending videos for the hashtag london. Note that video downloading is a time and data rate consuming task, as a result we strongly recommend to use one hashtag at a time so as to avoid complications.
Top n hashtag occurrences
In the analytics folder, the file hashtag_frequencies.py will plot the frequencies of top occurring hashtags in a given set of posts.
Assume we want to plot the graph of top 20 occurring hashtags in the downloaded posts of the hashtag london.
- Plotting the saving the image as a png file:
python3 hashtag_frequencies.py -p ../data/london/posts/data.json 20 -v
The figure above shows the top 20 occurring hashtags among all the posts downloaded for the hashtag london. Clearly, the highest occurrence will be of the hashtag london as the file data/london/posts/data.json contain all the posts with hashtag london.
- Printing the result in the shell:
python3 hashtag_frequencies.py -d ../data/london/posts/data.json 20 -v
The same result of 1 is printed in the shell. The last column shows the ratio of the occurrence to the total posts.