davidteather / TikTok-Api

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

CHALLENGE HASHTAG DOES NOT EXIST #752

Closed Harryhb1 closed 2 years ago

Harryhb1 commented 2 years ago

Hey. Trying to scrape videos through a hashtag with original sound. It seems that the request fails after a few attempts with a variation in total tiktoks requested (sometimes get 40 or 140).

The error is as follows, Exception has occurred: TikTokNotFoundError (note: full exception trace is shown but execution is paused at: ) Challenge funny does not exist

# I have tried both, the second ones gets further
api = TikTokApi.get_instance(use_selenium=True, executablePath="chromedriver_win32/chromedriver.exe", custom_verifyFp="ku3ta3mh_Gw9RP03S_uhb1_4YBD_Atrl_r6s7OcCvakHB")
api = TikTokApi()

# estimates the number of tiktoks, Average tiktok is around 15s
estimatedcount = int((length * 60) / float(15))
videoduration = 0

# Repeats until destied length is reached 
while (length / float(60)) < length:
    estimatedcount += 10
    chosentiktoks = []

    tiktoks = api.by_hashtag(hashtag=videohashtag, count=estimatedcount)

    for tiktok in tiktoks:
        if tiktok["music"]["title"] == "original sound":
            videoduration += int(tiktok["video"]["duration"])
            chosentiktoks.append(tiktok)
            print(tiktok)
davidteather commented 2 years ago

Think it throws this error when you make too many requests, V4.1.0 might help