davidteather / TikTok-Api

The Unofficial TikTok API Wrapper In Python
https://davidteather.github.io/TikTok-Api
MIT License
4.76k stars 960 forks source link

Just Want Text #1114

Open TebuKanaeru opened 7 months ago

TebuKanaeru commented 7 months ago

From the script below, can we only get text/comments from the user?

from TikTokApi import TikTokApi import asyncio import os

video_id = 7331767529976745234 ms_token = os.environ.get("ms_token", None) # set your own ms_token

context_options = { 'viewport' : { 'width': 1280, 'height': 1024 }, 'user_agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36' }

async def get_comments(): async with TikTokApi() as api: await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3, headless=False) video = api.video(id=video_id) count = 0 async for comment in video.comments(count=100): print(comment) print(comment.as_dict)

if name == "main": asyncio.run(get_comments())