networkdynamics / pytok

A web scraper for TikTok using Playwright
59 stars 6 forks source link

videos(count=x) not working #6

Open Dr-Yes opened 6 months ago

Dr-Yes commented 6 months ago

I'm trying to only get 20 videos from a user so I changed the example like so:

`import asyncio import json

from pytok.tiktok import PyTok

async def main(): async with PyTok() as api: user = api.user(username="therock") user_data = await user.info()

    videos = []
    videos_bytes = []
    async for video in user.videos(count=20):
        video_data = await video.info()
        videos.append(video_data)

    assert len(videos) > 0, "No videos found"
    with open("rock.json", "w") as f:
        json.dump(videos, f)

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

It prints "Failed to get videos all at once, trying in batches..." and returns 32 videos for this user and 35 for a different one I tried. Is async the problem? edit: can't get the code markdown to work, but I hope it's readable enough. Only thing I changed is add count=20 to videos parameter

bendavidsteel commented 5 months ago

This is happening because there are not enough checks on the video method to ensure the number of videos returned is at or below the count number. I don't have time to fix this right now, so please feel free to create a PR!