我想获取特定频道的所有视频网址。我认为 json 与 python 或 java 将是一个不错的选择。我可以使用以下代码获取最新视频,但如何获取所有视频链接(>500)?
import urllib, json
author = 'Youtube_Username'
inp = urllib.urlopen(r'http://gdata.youtube.com/feeds/api/videos?max-results=1&alt=json&orderby=published&author=' + author)
resp = json.load(inp)
inp.close()
first = resp['feed']['entry'][0]
print first['title'] # video title
print first['link'][0]['href'] #url
原文由 Johnny 发布,翻译遵循 CC BY-SA 4.0 许可协议
将 max-results 从 1 增加到您想要的任意数量,但要注意他们不建议在一次调用中获取太多结果,并且会将您限制在 50 个( https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters )。
相反,您可以考虑以 25 个为一组抓取数据,例如,通过更改起始索引直到没有数据返回。
编辑:这是我将如何做的代码