| Name | pyktok JSON |
| Version |
0.0.29
JSON |
| download |
| home_page | None |
| Summary | A package for collecting TikTok videos and metadata. |
| upload_time | 2024-08-12 14:03:35 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.8 |
| license | BSD 3-Clause License Copyright (c) 2022, Deen Freelon All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
## Pyktok
$\color{red} NOTE:\ 7/9/24:\ \textbf{save\\_tiktok\\_multi\\_page}\ and\ \textbf{save\\_tiktok\\_comments}\ work\\ again!$
**A simple module to collect video, text, and metadata from TikTok.**
We developed Pyktok ("pick-tock") because none of the existing TikTok data collection utilities we could find suited our needs. Pyktok pulls its data directly from the JSON objects embedded in Tiktok pages and from hidden APIs with no public documentation. Here are its major features:
- Download TikTok videos
- Download video metadata
- Download around 30 videos and/or metadata lines from hashtag, user, and the "You May Like" sections of video pages (you can try to specify the exact number but TikTok doesn't always follow it exactly)
- Download video comments
- Download full TikTok JSON data objects (in case you want to extract data from parts of the object not included in the above functions)
**Like Pyktok? Want to say thanks (and help fund future updates)? I accept [Venmo](https://venmo.com/Deen-Freelon) and [Cash App](https://cash.app/$dfreelon).**
R users, check out [traktok](https://github.com/JBGruber/traktok), an R port of Pyktok.
This program may stop working suddenly if TikTok changes how it stores its data (see [Freelon, 2018](https://osf.io/preprints/socarxiv/56f4q/)). Some functions may require you to be logged in to TikTok, which means they may not work on cloud servers that don't have Chrome or Firefox installed.
TikTok now offers an official research API to US-based academics--[you can apply for access here](https://developers.tiktok.com/products/research-api/).
Please note that [a number of US states have banned TikTok on state-owned devices](https://www.reuters.com/world/us/wisconsin-governor-signs-order-banning-tiktok-state-devices-2023-01-12/), which may include IT resources provided by state universities. Individuals employed by such institutions are advised to use Pyktok only within applicable laws and regulations.
**Installation**
```pip install pyktok```
**Requirements**
Pyktok relies on the following external packages:
- [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/)
- [browser-cookie3](https://pypi.org/project/browser-cookie3/)
- [Numpy](https://numpy.org/)
- [Pandas](https://pandas.pydata.org/)
- [Requests](https://pypi.org/project/requests/)
- [Streamlit](https://streamlit.io/)
- [TikTokApi](https://github.com/davidteather/TikTok-Api)
**Usage**
```python
import pyktok as pyk
pyk.specify_browser('chrome') #browser specification may or may not be necessary depending on your local settings
```
Historically it has been prudent to run the `specify_browser` function first to initialize Pyktok with a cookie from your browser of choice (e.g. 'firefox,' 'edge' etc.). However, recent developments indicate this may not be necessary for all users. YMMV.
Please note that functions that start with "get" will return data to working memory, while those starting with "save" will save data to disk without returning anything.
To download a single TikTok video and one line of metadata to the file "video_data.csv" (`'chrome'` can be changed to `'firefox'` if necessary):
```python
pyk.save_tiktok('https://www.tiktok.com/@tiktok/video/7106594312292453675?is_copy_url=1&is_from_webapp=v1',
True,
'video_data.csv',
'chrome')
```
To download another TikTok video and add its metadata to the same file as above:
```python
pyk.save_tiktok('https://www.tiktok.com/@tiktok/video/7011536772089924869?is_copy_url=1&is_from_webapp=v1',
True,
'video_data.csv',
'chrome')
```
To download metadata ONLY from the video URLs used in the preceding two lines of code (to also download the videos, change ```False``` to ```True```). If TikTok autobans the scraper, try changing the 1 to a higher number to increase the number of seconds between executions.
```python
tiktok_videos = ['https://www.tiktok.com/@tiktok/video/7106594312292453675?is_copy_url=1&is_from_webapp=v1',
'https://www.tiktok.com/@tiktok/video/7011536772089924869?is_copy_url=1&is_from_webapp=v1']
pyk.save_tiktok_multi_urls(tiktok_videos,
False,
'tiktok_data.csv',
1)
```
To download around 30 metadata lines from a *user* page (you can get the videos by setting `save_video` to `True`):
```python
pyk.save_tiktok_multi_page('tiktok',ent_type='user',save_video=False,metadata_fn='tiktok.csv')
```
If this or the following two functions delivers an `EmptyResponseException`, try setting `headless=False`.
To download around 30 metadata lines from a *hashtag* page:
```python
pyk.save_tiktok_multi_page('datascience',ent_type='hashtag',save_video=False,metadata_fn='datascience.csv')
```
To download around 30 metadata lines from related videos from a *video* page:
```python
pyk.save_tiktok_multi_page('https://www.tiktok.com/@tiktok/video/7106594312292453675',ent_type='video_related',save_video=False,metadata_fn='7106594312292453675.csv')
```
To download around 30 comments from a video (the underlying code interprets `comment_count` rather loosely):
```python
pyk.save_tiktok_comments('https://www.tiktok.com/@tiktok/video/7106594312292453675',comment_count=30,save_comments=True,return_comments=False)
```
To get an individual video's JSON object:
```python
tt_json = pyk.alt_get_tiktok_json('https://www.tiktok.com/@tiktok/video/7011536772089924869?is_copy_url=1&is_from_webapp=v1')
```
TikTok's servers may not love it if you run some of the above functions 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.
Pyktok can also be run from a browser window using `streamlit`. To do so, simply navigate to your `pyktok` directory in a command prompt (it should contain the file `app.py`) and run `streamlit run app.py`. This should pop up a browser window that allows you to control Pyktok using graphical affordances.
Mostly written by [@dfreelon](https://github.com/dfreelon/) with contributions from (in chronological order):
- [@pkreissel](https://github.com/pkreissel)
- [@p-bach](https://github.com/p-bach)
- [@TimoBaeuerle](https://github.com/TimoBaeuerle)
- [@christinapwalker](https://github.com/christinapwalker)
- [@codeteme](https://github.com/codeteme)
- [@dphiffer](https://github.com/dphiffer)
- [@BillyBSig](https://github.com/BillyBSig)
- [@tomasruizt](https://github.com/tomasruizt)
Raw data
{
"_id": null,
"home_page": null,
"name": "pyktok",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Deen Freelon <dfreelon@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/13/23/15838a76fe774299cadf2f6af344186e95681611b27cee14c463324f1275/pyktok-0.0.29.tar.gz",
"platform": null,
"description": "## Pyktok\n$\\color{red} NOTE:\\ 7/9/24:\\ \\textbf{save\\\\_tiktok\\\\_multi\\\\_page}\\ and\\ \\textbf{save\\\\_tiktok\\\\_comments}\\ work\\\\ again!$\n\n**A simple module to collect video, text, and metadata from TikTok.**\n\nWe developed Pyktok (\"pick-tock\") because none of the existing TikTok data collection utilities we could find suited our needs. Pyktok pulls its data directly from the JSON objects embedded in Tiktok pages and from hidden APIs with no public documentation. Here are its major features:\n\n - Download TikTok videos\n - Download video metadata\n - Download around 30 videos and/or metadata lines from hashtag, user, and the \"You May Like\" sections of video pages (you can try to specify the exact number but TikTok doesn't always follow it exactly)\n - Download video comments\n - Download full TikTok JSON data objects (in case you want to extract data from parts of the object not included in the above functions)\n\n**Like Pyktok? Want to say thanks (and help fund future updates)? I accept [Venmo](https://venmo.com/Deen-Freelon) and [Cash App](https://cash.app/$dfreelon).**\n\nR users, check out [traktok](https://github.com/JBGruber/traktok), an R port of Pyktok.\n\nThis program may stop working suddenly if TikTok changes how it stores its data (see [Freelon, 2018](https://osf.io/preprints/socarxiv/56f4q/)). Some functions may require you to be logged in to TikTok, which means they may not work on cloud servers that don't have Chrome or Firefox installed.\n\nTikTok now offers an official research API to US-based academics--[you can apply for access here](https://developers.tiktok.com/products/research-api/).\n\nPlease note that [a number of US states have banned TikTok on state-owned devices](https://www.reuters.com/world/us/wisconsin-governor-signs-order-banning-tiktok-state-devices-2023-01-12/), which may include IT resources provided by state universities. Individuals employed by such institutions are advised to use Pyktok only within applicable laws and regulations.\n\n**Installation**\n\n```pip install pyktok```\n\n**Requirements**\n\nPyktok relies on the following external packages:\n\n - [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/)\n - [browser-cookie3](https://pypi.org/project/browser-cookie3/)\n - [Numpy](https://numpy.org/)\n - [Pandas](https://pandas.pydata.org/)\n - [Requests](https://pypi.org/project/requests/)\n - [Streamlit](https://streamlit.io/)\n - [TikTokApi](https://github.com/davidteather/TikTok-Api)\n\n**Usage**\n\n```python\nimport pyktok as pyk\npyk.specify_browser('chrome') #browser specification may or may not be necessary depending on your local settings\n```\nHistorically it has been prudent to run the `specify_browser` function first to initialize Pyktok with a cookie from your browser of choice (e.g. 'firefox,' 'edge' etc.). However, recent developments indicate this may not be necessary for all users. YMMV.\n\nPlease note that functions that start with \"get\" will return data to working memory, while those starting with \"save\" will save data to disk without returning anything.\n\nTo download a single TikTok video and one line of metadata to the file \"video_data.csv\" (`'chrome'` can be changed to `'firefox'` if necessary):\n```python \npyk.save_tiktok('https://www.tiktok.com/@tiktok/video/7106594312292453675?is_copy_url=1&is_from_webapp=v1',\n\t True,\n 'video_data.csv',\n\t\t'chrome')\n``` \nTo download another TikTok video and add its metadata to the same file as above:\n```python \npyk.save_tiktok('https://www.tiktok.com/@tiktok/video/7011536772089924869?is_copy_url=1&is_from_webapp=v1',\n\t True,\n 'video_data.csv',\n\t\t'chrome')\n``` \nTo download metadata ONLY from the video URLs used in the preceding two lines of code (to also download the videos, change ```False``` to ```True```). If TikTok autobans the scraper, try changing the 1 to a higher number to increase the number of seconds between executions.\n```python\ntiktok_videos = ['https://www.tiktok.com/@tiktok/video/7106594312292453675?is_copy_url=1&is_from_webapp=v1',\n 'https://www.tiktok.com/@tiktok/video/7011536772089924869?is_copy_url=1&is_from_webapp=v1']\npyk.save_tiktok_multi_urls(tiktok_videos,\n False,\n \t 'tiktok_data.csv',\n \t 1)\n```\n\nTo download around 30 metadata lines from a *user* page (you can get the videos by setting `save_video` to `True`): \n\n```python \npyk.save_tiktok_multi_page('tiktok',ent_type='user',save_video=False,metadata_fn='tiktok.csv')\n```\n\nIf this or the following two functions delivers an `EmptyResponseException`, try setting `headless=False`.\n\nTo download around 30 metadata lines from a *hashtag* page: \n\n```python \npyk.save_tiktok_multi_page('datascience',ent_type='hashtag',save_video=False,metadata_fn='datascience.csv')\n```\n\nTo download around 30 metadata lines from related videos from a *video* page: \n\n```python \npyk.save_tiktok_multi_page('https://www.tiktok.com/@tiktok/video/7106594312292453675',ent_type='video_related',save_video=False,metadata_fn='7106594312292453675.csv')\n```\n\nTo download around 30 comments from a video (the underlying code interprets `comment_count` rather loosely): \n\n```python \npyk.save_tiktok_comments('https://www.tiktok.com/@tiktok/video/7106594312292453675',comment_count=30,save_comments=True,return_comments=False)\n```\n \nTo get an individual video's JSON object:\n```python\t\ntt_json = pyk.alt_get_tiktok_json('https://www.tiktok.com/@tiktok/video/7011536772089924869?is_copy_url=1&is_from_webapp=v1')\n```\n\nTikTok's servers may not love it if you run some of the above functions 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.\n\nPyktok can also be run from a browser window using `streamlit`. To do so, simply navigate to your `pyktok` directory in a command prompt (it should contain the file `app.py`) and run `streamlit run app.py`. This should pop up a browser window that allows you to control Pyktok using graphical affordances.\n\nMostly written by [@dfreelon](https://github.com/dfreelon/) with contributions from (in chronological order): \n- [@pkreissel](https://github.com/pkreissel)\n- [@p-bach](https://github.com/p-bach)\n- [@TimoBaeuerle](https://github.com/TimoBaeuerle)\n- [@christinapwalker](https://github.com/christinapwalker)\n- [@codeteme](https://github.com/codeteme)\n- [@dphiffer](https://github.com/dphiffer)\n- [@BillyBSig](https://github.com/BillyBSig)\n- [@tomasruizt](https://github.com/tomasruizt)\n",
"bugtrack_url": null,
"license": "BSD 3-Clause License Copyright (c) 2022, Deen Freelon All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
"summary": "A package for collecting TikTok videos and metadata.",
"version": "0.0.29",
"project_urls": {
"Homepage": "https://github.com/dfreelon/pyktok"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ea00b7c448175c0d1fbb1f05cc6e9c90977594d2a16362f99c1abc89b950d875",
"md5": "c185d31dd35a0e09c006188ad42e1098",
"sha256": "41c9a098ff28c0f38f111a39ebe02c912d7e484cfcb07328cd9be0512147ef8a"
},
"downloads": -1,
"filename": "pyktok-0.0.29-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c185d31dd35a0e09c006188ad42e1098",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 9677,
"upload_time": "2024-08-12T14:03:34",
"upload_time_iso_8601": "2024-08-12T14:03:34.371815Z",
"url": "https://files.pythonhosted.org/packages/ea/00/b7c448175c0d1fbb1f05cc6e9c90977594d2a16362f99c1abc89b950d875/pyktok-0.0.29-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "132315838a76fe774299cadf2f6af344186e95681611b27cee14c463324f1275",
"md5": "8bf5f0741c18d8c079a65d362dc60e34",
"sha256": "08e2db92056e00fe545ba43b93795552bc3620f9408c39aec92251f027f2cdf5"
},
"downloads": -1,
"filename": "pyktok-0.0.29.tar.gz",
"has_sig": false,
"md5_digest": "8bf5f0741c18d8c079a65d362dc60e34",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 11642,
"upload_time": "2024-08-12T14:03:35",
"upload_time_iso_8601": "2024-08-12T14:03:35.833476Z",
"url": "https://files.pythonhosted.org/packages/13/23/15838a76fe774299cadf2f6af344186e95681611b27cee14c463324f1275/pyktok-0.0.29.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-12 14:03:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dfreelon",
"github_project": "pyktok",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyktok"
}