栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

python:获取频道的所有youtube视频网址

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python:获取频道的所有youtube视频网址

将最大结果从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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/624828.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号