## Tiktok simple scraper
### Features
- Scrapes all the posts of a tiktok account
- Scrapes all the comments of a post
### Installation
```bash
pip install tiktok_simple_scraper
```
### Usage
You need to obtain a ms token and the "id" or "secuid" of the account.
The ms token is a token that is used to authenticate the requests to the tiktok api.
The "id" or "secuid" is the unique identifier of the account you want to scrape.
You can obtain the ms token and the "id" or "secuid" of the account by opening tiktok and in your browser console see the requests it makes (see the network tab)
![docs/ms_token_and_secuid.png](https://github.com/Eitol/tiktok_simple_scraper/blob/main/docs/ms_token_and_secuid.png?raw=true)
```python3
from datetime import datetime, timedelta
import os
from tiktok_simple_scraper.entities import ScraperOptions
from tiktok_simple_scraper.opts import LogCallbacks
from tiktok_simple_scraper.tiktok import TikTokAccountScraper
opts = ScraperOptions(
most_old_date=datetime.now() - timedelta(days=3 * 30),
max_comments_per_post=1000,
callbacks=LogCallbacks(),
check_account_in_storage=True,
)
ms_token = os.environ.get("MS_TOKEN")
scraper = TikTokAccountScraper(
ms_token=ms_token,
)
account_secuid = "MS4wLjABAAAAUgpIunuFPI8GMn_zdK8OXxV7LCY3sGClYMubx-GSpu_g75SB_Sb8nNxIKm3TytOX"
result = scraper.scrape(account_secuid, opts)
print(result.json())
```
Output example:
```json5
{
"name_to_show": "BancoEstado Oficial",
"id": "MS4wLjABAAAAUgpIunuFPI8GMn_zdK8OXxV7LCY3sGClYMubx-GSpu_g75SB_Sb8nNxIKm3TytOX",
"social_media": "TIKTOK",
"followers_count": 0,
"countries": [],
"posts": [
{
"id": "7362193936972090629",
"sec_id": null,
"url": "7362193936972090629",
"hashtags": [],
"text": "¿Quién más así? #foryou #Bancoestado #pedropedropedropedro #trend #trending ",
"type": "VIDEO",
"date": "2024-04-26T11:12:36",
"reactions": [
{
"type": "LIKE",
"count": 113
}
],
"comments": [
{
"text": "Es viernes nuestro cuerpo lo sabe",
"user": "elaahumada",
"date": "2024-04-26T18:51:02",
"url": "7362312008602256133",
"reactions": [
{
"type": "LIKE",
"count": 0
}
],
"replies": [],
"sentiments": null,
"user_name": "Ela Ahumada",
"user_metadata": {
"sec_uid": "MS4wLjABAAAALllrU5MkSPTaH2oO8ByCERShguFrTi20Z9maUWQi7Ob8ETi7XuN1fTGx_Wg3gaJr",
"id": "239504324559560704"
},
"score": null
},
// more comments...
],
"reaction_count": 113,
"share_count": 35,
"view_count": 12900,
"total_comments": 0
},
// more posts...
]
}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Eitol/tiktok_simple_scraper",
"name": "tiktok-simple-scraper",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Hector Oliveros",
"author_email": "hector.oliveros.leon@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/27/2c/f3ef55b52159b495cdd47a5c70b521a8db84017bb4aeb9c00a6f3ff2ba0b/tiktok_simple_scraper-0.0.9.tar.gz",
"platform": null,
"description": "## Tiktok simple scraper\n\n### Features\n- Scrapes all the posts of a tiktok account\n- Scrapes all the comments of a post\n\n### Installation\n```bash\npip install tiktok_simple_scraper\n```\n\n### Usage\n\nYou need to obtain a ms token and the \"id\" or \"secuid\" of the account.\nThe ms token is a token that is used to authenticate the requests to the tiktok api.\nThe \"id\" or \"secuid\" is the unique identifier of the account you want to scrape.\nYou can obtain the ms token and the \"id\" or \"secuid\" of the account by opening tiktok and in your browser console see the requests it makes (see the network tab)\n\n![docs/ms_token_and_secuid.png](https://github.com/Eitol/tiktok_simple_scraper/blob/main/docs/ms_token_and_secuid.png?raw=true)\n\n```python3\nfrom datetime import datetime, timedelta\nimport os\n\nfrom tiktok_simple_scraper.entities import ScraperOptions\nfrom tiktok_simple_scraper.opts import LogCallbacks\nfrom tiktok_simple_scraper.tiktok import TikTokAccountScraper\n\nopts = ScraperOptions(\n most_old_date=datetime.now() - timedelta(days=3 * 30),\n max_comments_per_post=1000,\n callbacks=LogCallbacks(),\n check_account_in_storage=True,\n)\n\nms_token = os.environ.get(\"MS_TOKEN\")\nscraper = TikTokAccountScraper(\n ms_token=ms_token,\n)\naccount_secuid = \"MS4wLjABAAAAUgpIunuFPI8GMn_zdK8OXxV7LCY3sGClYMubx-GSpu_g75SB_Sb8nNxIKm3TytOX\"\nresult = scraper.scrape(account_secuid, opts)\nprint(result.json())\n```\n\nOutput example:\n\n```json5\n{\n \"name_to_show\": \"BancoEstado Oficial\",\n \"id\": \"MS4wLjABAAAAUgpIunuFPI8GMn_zdK8OXxV7LCY3sGClYMubx-GSpu_g75SB_Sb8nNxIKm3TytOX\",\n \"social_media\": \"TIKTOK\",\n \"followers_count\": 0,\n \"countries\": [],\n \"posts\": [\n {\n \"id\": \"7362193936972090629\",\n \"sec_id\": null,\n \"url\": \"7362193936972090629\",\n \"hashtags\": [],\n \"text\": \"\u00bfQui\u00e9n m\u00e1s as\u00ed? #foryou #Bancoestado #pedropedropedropedro #trend #trending \",\n \"type\": \"VIDEO\",\n \"date\": \"2024-04-26T11:12:36\",\n \"reactions\": [\n {\n \"type\": \"LIKE\",\n \"count\": 113\n }\n ],\n \"comments\": [\n {\n \"text\": \"Es viernes nuestro cuerpo lo sabe\",\n \"user\": \"elaahumada\",\n \"date\": \"2024-04-26T18:51:02\",\n \"url\": \"7362312008602256133\",\n \"reactions\": [\n {\n \"type\": \"LIKE\",\n \"count\": 0\n }\n ],\n \"replies\": [],\n \"sentiments\": null,\n \"user_name\": \"Ela Ahumada\",\n \"user_metadata\": {\n \"sec_uid\": \"MS4wLjABAAAALllrU5MkSPTaH2oO8ByCERShguFrTi20Z9maUWQi7Ob8ETi7XuN1fTGx_Wg3gaJr\",\n \"id\": \"239504324559560704\"\n },\n \"score\": null\n },\n // more comments...\n ],\n \"reaction_count\": 113,\n \"share_count\": 35,\n \"view_count\": 12900,\n \"total_comments\": 0\n },\n // more posts...\n ]\n}\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple scraper for Tiktok",
"version": "0.0.9",
"project_urls": {
"Homepage": "https://github.com/Eitol/tiktok_simple_scraper"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b034dc1f909c1b78ec4d201635fb8e0b35bccd42be66d73511ad77c2327aa978",
"md5": "8ff4593fe31f5a3c021c9befe29550a3",
"sha256": "144874e5c755318a832bc23d494e77294a06ac8131c0cabee81943cbcd6a66f0"
},
"downloads": -1,
"filename": "tiktok_simple_scraper-0.0.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8ff4593fe31f5a3c021c9befe29550a3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 15931,
"upload_time": "2024-06-14T05:14:06",
"upload_time_iso_8601": "2024-06-14T05:14:06.039973Z",
"url": "https://files.pythonhosted.org/packages/b0/34/dc1f909c1b78ec4d201635fb8e0b35bccd42be66d73511ad77c2327aa978/tiktok_simple_scraper-0.0.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "272cf3ef55b52159b495cdd47a5c70b521a8db84017bb4aeb9c00a6f3ff2ba0b",
"md5": "840be16e3940815099b71df0280f1c57",
"sha256": "e03ba0d3ca94c9ae049a7808b8f9a03662656cbcf87686d7b77dc4f4bcb71c8b"
},
"downloads": -1,
"filename": "tiktok_simple_scraper-0.0.9.tar.gz",
"has_sig": false,
"md5_digest": "840be16e3940815099b71df0280f1c57",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 15650,
"upload_time": "2024-06-14T05:14:07",
"upload_time_iso_8601": "2024-06-14T05:14:07.190782Z",
"url": "https://files.pythonhosted.org/packages/27/2c/f3ef55b52159b495cdd47a5c70b521a8db84017bb4aeb9c00a6f3ff2ba0b/tiktok_simple_scraper-0.0.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-14 05:14:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Eitol",
"github_project": "tiktok_simple_scraper",
"github_not_found": true,
"lcname": "tiktok-simple-scraper"
}