【发布时间】:2019-05-12 12:41:26
【问题描述】:
我创建了这段代码来获得 500 个结果,而不是通常来自 youtube API 的 50 个结果
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,10) < 10。 -
很清楚为什么和什么不工作。你的代码中只有 1 个地方有 '
-
另外,
maxresults的最大项目数为 50。见stackoverflow.com/a/54030747/4092887
标签: python api youtube youtube-data-api