forked from Evil0ctal/Douyin_TikTok_Download_API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
35 lines (26 loc) · 1.11 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from crawlers.tiktok.web.web_crawler import TikTokWebCrawler # Import TikTokWebCrawler class
import asyncio
import json
import time
api = TikTokWebCrawler()
async def main() -> dict:
# count = 20
# # posts = []
# result = await api.fetch_post_comment("7426227701096123655", count)
# # posts.extend(result.get("comments", []))
# # Write initial result to the JSON file
# for comment in result.get("comments", []):
# with open("cmt.txt", "a") as f:
# f.write(comment.get("text") + "\n")
# # Fetch additional comments if available
# while result.get("has_more", False) and result.get("cursor"):
# time.sleep(5)
# cursor = result.get("cursor")
# result = await api.fetch_post_comment("7426227701096123655", cursor=cursor)
# # posts.extend(result.get("comments", []))
# for comment in result.get("comments", []):
# with open("cmt.txt", "a") as f:
# f.write(comment.get("text") + "\n")
result = await api.get_search_video("hieuthuhai", offset=0, count=20)
print(result)
asyncio.run(main())