{"id":28376966,"url":"https://github.com/bellingcat/tiktok-hashtag-analysis","last_synced_at":"2025-06-26T18:31:49.336Z","repository":{"id":38192788,"uuid":"395059512","full_name":"bellingcat/tiktok-hashtag-analysis","owner":"bellingcat","description":"Provides tools to analyze hashtags within posts scraped from TikTok.","archived":false,"fork":false,"pushed_at":"2024-06-23T19:18:39.000Z","size":205,"stargazers_count":335,"open_issues_count":11,"forks_count":42,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-05-30T00:42:02.214Z","etag":null,"topics":["command-line","open-source-research","python","scraper","social-network","tiktok"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/tiktok-hashtag-analysis/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bellingcat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-08-11T16:57:02.000Z","updated_at":"2025-05-30T00:11:05.000Z","dependencies_parsed_at":"2024-03-12T00:42:45.708Z","dependency_job_id":"ba58472a-4e3b-4fa4-b727-bfa9071e9423","html_url":"https://github.com/bellingcat/tiktok-hashtag-analysis","commit_stats":{"total_commits":131,"total_committers":6,"mean_commits":"21.833333333333332","dds":0.4427480916030534,"last_synced_commit":"06b4a74c7d4b87576fe611ac808ff01d4f746395"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/bellingcat/tiktok-hashtag-analysis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bellingcat%2Ftiktok-hashtag-analysis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bellingcat%2Ftiktok-hashtag-analysis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bellingcat%2Ftiktok-hashtag-analysis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bellingcat%2Ftiktok-hashtag-analysis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bellingcat","download_url":"https://codeload.github.com/bellingcat/tiktok-hashtag-analysis/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bellingcat%2Ftiktok-hashtag-analysis/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262122687,"owners_count":23262459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line","open-source-research","python","scraper","social-network","tiktok"],"created_at":"2025-05-30T00:38:47.763Z","updated_at":"2025-06-26T18:31:49.302Z","avatar_url":"https://github.com/bellingcat.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TikTok hashtag analysis toolset \n\nThe tool helps to download posts and videos from TikTok for a given set of hashtags over a period of time. Users can create a growing database of posts for specific hashtags which can then be used for further hashtag analysis. It uses the [TikTokApi](https://github.com/davidteather/TikTok-Api) Python package  to download the posts and uses [yt-dlp](https://github.com/yt-dlp/yt-dlp) to download the videos.\n\n[![PyPI version](https://badge.fury.io/py/tiktok-hashtag-analysis.svg)](https://badge.fury.io/py/tiktok-hashtag-analysis)\n\n## Pre-requisites\n1. Make sure you have Python 3.9 or a later version installed\n2. Install the tool with pip: `pip install tiktok-hashtag-analysis`\n   - Alternatively you can install directly from the latest version on GitHub: `pip install git+https://github.com/bellingcat/tiktok-hashtag-analysis`\n3. Make sure [Playwright](https://playwright.dev/python/docs/intro) is properly installed by running the command `python -m playwright install`\n\nYou should now be ready to start using it.\n\n## About the tool\n### Command-line arguments\n```\nusage: tiktok-hashtag-analysis [-h] [--file FILE] [-d] [--number NUMBER] [-p] [-t] [--output-dir OUTPUT_DIR] [--config CONFIG] [--log LOG] [--limit LIMIT] [-v] [--headed] [hashtags ...]\n\nAnalyze hashtags within posts scraped from TikTok.\n\npositional arguments:\n  hashtags              List of hashtags to scrape\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --file FILE           File name containing list of hashtags to scrape\n  -d, --download        Download video files corresponding to scraped posts\n  --number NUMBER       The number of co-occurring hashtags to analyze\n  -p, --plot            Plot the most common co-occurring hashtags\n  -t, --table           Print a table of the most common co-occurring hashtags\n  --output-dir OUTPUT_DIR\n                        Directory to save scraped data and visualizations to\n  --config CONFIG       File name of configuration file to store TikTok credentials to\n  --log LOG             File to write logs to\n  --limit LIMIT         Maximum number of videos to download for each hashtag\n  -v, --verbose         Increase output verbosity\n  --headed              Don't use headless version of TikTok scraper\n```\n\n### Structure of output data\n```\n$ tree ../data\n../data\n├── london\n│   ├── plots\n│   ├── posts.json\n│   └── media\n├── newyork\n│   ├── plots\n│   ├── posts.json\n│   └── media\n└── paris\n│   ├── plots\n│   ├── posts.json\n│   └── media\n```\n\n\nThe `data` folder contains all the downloaded data as shown in the tree diagram above. \n- Each hashtag has a folder with two subfolders `plots` and `media` that store plots of the most common co-occurring hashtags, and media downloaded from the posts. The posts are stored in the `posts.json` file, and downloaded media is stored as `.mp4` files (for videos) or audio and image files (for image galleries) in the `media` folder.\n\n\n## How to use\n### Post downloading\nRunning the `tiktok-hashtag-analysis` command with the following options will scrape posts that contain the hashtags `#london`, `#paris`, or `#newyork`:\n\n    tiktok-hashtag-analysis london paris newyork\n\nand will produce an output similar to the following log:\n\n    $ tiktok-hashtag-analysis download london paris newyork\n    Hashtags to scrape: ['london', 'paris', 'newyork']\n    Scraped 963 posts containing the hashtag 'london'\n    Scraped 961 posts containing the hashtag 'paris'\n    Scraped 940 posts containing the hashtag 'newyork'\n    Successfully scraped 2864 total entries\n\n- The list of hashtags to scrape is specified as a positional argument\n\n### Video downloading\nRunning the `tiktok-hashtag-analysis` script with the following options will scrape trending posts containing the hashtag `#london`:\n`tiktok-hashtag-analysis london --download`\n\n- The `--download` flag specifies that video files for scraped posts should be downloaded\n\nNote that video downloading is a time and data rate consuming task, as a result we recommend using one hashtag at a time when using the `--download` flag to avoid complications.\n\n## Analyzing results \n### Most common co-occurring hashtags\nIn addition to scraping data and downloading media, the `tiktok-hashtag-analysis` script can also analyze the frequencies of the most common co-occurring hashtags in a given set of posts.\n\nAssume we want to analyze the 20 most frequently co-occurring hashtags in the downloaded posts of the `#london` hashtag.\n\n- The results can be plotted and saved as a PNG file by executing the following command: \n\n    `tiktok-hashtag-analysis london --number 20 --plot`\n    \n    which will produce a figure similar to that shown below:\n    \u003cp align=\"center\"\u003e\n        \u003cimg src=\"https://user-images.githubusercontent.com/18430739/166878928-d146b352-b68c-4ab4-bd2c-feb2f0140df9.png\" height=\"500\" alt=\"Top 20 most frequent common hashtags in posts containing the #london hashtag\"\u003e\n    \u003c/p\u003e\n    \n    In the above plot, the highest occurrence is the `#fyp` hashtag, which is tagged in more than half of all posts containing the `#london` hashtag.\n\n- The results can be displayed in tabular form by executing the following command:\n\n    `tiktok-hashtag-analysis london --number 20 --table`\n\n    which will produce a terminal output similar to the following:\n    ```\n    Co-occurring hashtags for #london posts\n    Rank     Hashtag                        Occurrences     Frequency      \n    0        london                         881             1.0000\n    1        fyp                            399             0.4529\n    2        uk                             174             0.1975\n    3        foryou                         168             0.1907\n    4        viral                          152             0.1725\n    5        foryoupage                     137             0.1555\n    6        fypシ                           73              0.0829\n    7        funny                          54              0.0613\n    8        tiktok                         43              0.0488\n    9        trending                       43              0.0488\n    10       british                        41              0.0465\n    11       england                        38              0.0431\n    12       xyzbca                         34              0.0386\n    13       fy                             33              0.0375\n    14       usa                            33              0.0375\n    15       love                           29              0.0329\n    16       comedy                         25              0.0284\n    17       royalfamily                    23              0.0261\n    18       queen                          23              0.0261\n    19       queenelizabeth                 22              0.0250\n    Total posts: 881\n    ```\n\n    The `Frequency` column shows the ratio of the occurrence to the total number of downloaded posts.\n\n### Contributing\nTo run the build-in tests in the `tests/` directory, first install the test dependency packages:\n\n```\npip install .[dev]\n```\n\nand then run the tests using the following command:\n\n```\npytest\n```\n\nThis repo uses [black](https://github.com/psf/black) to format source code and [mypy](https://mypy.readthedocs.io/en/stable/) for static type checking. Before submitting a pull request, please run both tools on the source code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbellingcat%2Ftiktok-hashtag-analysis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbellingcat%2Ftiktok-hashtag-analysis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbellingcat%2Ftiktok-hashtag-analysis/lists"}