将最大结果从1增加到您想要的任何数目,但是请注意,他们不建议一次通话就抓住太多,并且将您限制为50(https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters)。
取而代之的是,您可以考虑通过更改起始索引直到没有索引返回的方式,以25个为单位抓取数据。
编辑:这是我该怎么做的代码
import urllib, jsonauthor = 'Youtube_Username'foundAll = Falseind = 1videos = []while not foundAll: inp = urllib.urlopen(r'http://gdata.youtube.com/feeds/api/videos?start-index={0}&max-results=50&alt=json&orderby=published&author={1}'.format( ind, author ) ) try: resp = json.load(inp) inp.close() returnedVideos = resp['feed']['entry'] for video in returnedVideos: videos.append( video ) ind += 50 print len( videos ) if ( len( returnedVideos ) < 50 ): foundAll = True except: #catch the case where the number of videos in the channel is a multiple of 50 print "error" foundAll = Truefor video in videos: print video['title'] # video title print video['link'][0]['href'] #url
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)