Russell-Newton / TikTokPy

Extract data from TikTok without needing any login information or API keys.
https://pypi.org/project/tiktokapipy/
MIT License
214 stars 28 forks source link

[QUESTION] How to retrieve more than 30 videos #43

Closed RenHong-HC closed 1 year ago

RenHong-HC commented 1 year ago

I have two needs now

The code for the first case is as follows

        with TikTokAPI() as api:
            user = api.user("morifuntool", video_limit=2000)

            for video in user.videos:
                print(f"URL:https://www.tiktok.com/@morifuntool/video/{video.id},Time:{video.create_time}")

The video data can be obtained normally, but there are only 30 videos. How can I get all videos?

The code for the second case is as follows

         with TikTokAPI() as api:
            challenge = api.challenge("OutfitIdeas")
            for video in challenge.videos:
                print(f"https://www.tiktok.com/@morifuntool/video/{video.id}")
                print(video.create_time)

The video data can be obtained normally, but there are only 40+ videos. How can I get all videos?

Russell-Newton commented 1 year ago

There currently isn't a great way to get all 40+ videos. The way that is currently implemented is to increase the scroll_down_time parameter in the API constructor. Set that to something like 10, and you'll collect more videos. The exact amount isn't deterministic though, unfortunately.

RenHong-HC commented 1 year ago

@Russell-Newton Thank you for your reply,I will try this parameter

Russell-Newton commented 1 year ago

I think the changes I've been working on with v0.2 might fix this issue. It could be worth checking out:

pip install -U git+https://github.com/Russell-Newton/TikTokPy.git@v0.2-overhaul I removed the scrolling parameters, but it should (fingers crossed) work without any API constructor parameters. You should be able to get away with:

with TikTokAPI() as api:
    user = api.user("tiktok")
    for video in user.videos:
        # do something

This should iterate over all of a user's videos. You can limit this using the video_limit parameter in api.user or using the limit method attached to user.videos (for video in user.videos.limit(30)).

@RenHong-HC if you would be willing to try out the WIP changes to see if it works, it could be very helpful for solving this issue. The changes work for me, but it's worth checking if it works for you.

jasonxubw commented 1 year ago

@Russell-Newton v0.2 resolved the issue. Thank you!!

Russell-Newton commented 1 year ago

Awesome! I'll close this issue once I release v0.2.

Russell-Newton commented 1 year ago

This issue should be resolved in the official version 0.2.0 release. I'm closing this issue as resolved.