Результаты API YouTube возвращают только 50 - PullRequest
0 голосов
/ 11 декабря 2018

Я создал этот код, чтобы получить 500 результатов вместо обычных 50 от youtube API

def youtube_search_paginated(q, max_results=50, pages=10, 
                             order="viewCount", token=None, 
                             location=None, location_radius=None):
    page = (1,10)
    token, results = youtube_search(q, max_results, order, 
                                   None, location, location_radius)
    yield (page, results)
    while token and page < pages:
        (token, results) = youtube_search(q, max_results, order, 
                                          token, location, location_radius)
        page += 1
        yield (page, results)

Затем при попытке реализовать его с помощью следующего кода я запускаю следующую ошибку:

(next_page_token, video_results) = youtube_search_paginated(" ")
print(len(video_results), "videos found")
print("---")
pprint.pprint(video_results[0])
print("---")
for v in video_results:
    print("{} views\t{}\t{}".format(v['viewCount'], 
    v['videoId'], v['title'][:9999]))


>>TypeError: '<' not supported between instances of 'tuple' and 'int'

1 Ответ

0 голосов
/ 11 декабря 2018

Ваша переменная page неверна.

def youtube_search_paginated(q, max_results=50, pages=10, 
order="viewCount", token=None, location=None, 
location_radius=None):
    page = 0 # <--- Change this one
    (token, results) = youtube_search(q, max_results, order, 
    None, location, location_radius)
    yield (page, results)
    while token and page < pages:
        (token, results) = youtube_search(q, max_results, order, 
        token, location, location_radius)
        page += 1
    yield (page, results)
...