<tfoot id='L02ZP'></tfoot>

      • <bdo id='L02ZP'></bdo><ul id='L02ZP'></ul>
      <legend id='L02ZP'><style id='L02ZP'><dir id='L02ZP'><q id='L02ZP'></q></dir></style></legend>

    1. <i id='L02ZP'><tr id='L02ZP'><dt id='L02ZP'><q id='L02ZP'><span id='L02ZP'><b id='L02ZP'><form id='L02ZP'><ins id='L02ZP'></ins><ul id='L02ZP'></ul><sub id='L02ZP'></sub></form><legend id='L02ZP'></legend><bdo id='L02ZP'><pre id='L02ZP'><center id='L02ZP'></center></pre></bdo></b><th id='L02ZP'></th></span></q></dt></tr></i><div id='L02ZP'><tfoot id='L02ZP'></tfoot><dl id='L02ZP'><fieldset id='L02ZP'></fieldset></dl></div>

      <small id='L02ZP'></small><noframes id='L02ZP'>

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

        python: get all youtube video urls of a channel(python:获取频道的所有 youtube 视频网址)
            <bdo id='LFgs4'></bdo><ul id='LFgs4'></ul>
          • <small id='LFgs4'></small><noframes id='LFgs4'>

            <legend id='LFgs4'><style id='LFgs4'><dir id='LFgs4'><q id='LFgs4'></q></dir></style></legend>
              <tbody id='LFgs4'></tbody>

            • <tfoot id='LFgs4'></tfoot>
                  <i id='LFgs4'><tr id='LFgs4'><dt id='LFgs4'><q id='LFgs4'><span id='LFgs4'><b id='LFgs4'><form id='LFgs4'><ins id='LFgs4'></ins><ul id='LFgs4'></ul><sub id='LFgs4'></sub></form><legend id='LFgs4'></legend><bdo id='LFgs4'><pre id='LFgs4'><center id='LFgs4'></center></pre></bdo></b><th id='LFgs4'></th></span></q></dt></tr></i><div id='LFgs4'><tfoot id='LFgs4'></tfoot><dl id='LFgs4'><fieldset id='LFgs4'></fieldset></dl></div>

                  本文介绍了python:获取频道的所有 youtube 视频网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想获取特定频道的所有视频网址.我认为 json 与 python 或 java 将是一个不错的选择.我可以使用以下代码获取最新视频,但是如何获取所有视频链接 (>500)?

                  I want to get all video url's of a specific channel. I think json with python or java would be a good choice. I can get the newest video with the following code, but how can I get ALL video links (>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
                  

                  推荐答案

                  将 max-results 从 1 增加到你想要的任意数量,但要注意他们不建议一次调用太多,并且会将你限制在 50 (https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters).

                  Increase max-results from 1 to however many you want, but beware they don't advise grabbing too many in one call and will limit you at 50 (https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters).

                  相反,您可以考虑以 25 个为一组抓取数据,例如,通过更改 start-index 直到没有返回.

                  Instead you could consider grabbing the data down in batches of 25, say, by changing the start-index until none came back.

                  这是我将如何做的代码

                  import urllib, json
                  author = 'Youtube_Username'
                  
                  foundAll = False
                  ind = 1
                  videos = []
                  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 = True
                  
                  for video in videos:
                      print video['title'] # video title
                      print video['link'][0]['href'] #url
                  

                  这篇关于python:获取频道的所有 youtube 视频网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                    <tbody id='W6pnV'></tbody>
                    • <bdo id='W6pnV'></bdo><ul id='W6pnV'></ul>

                      <i id='W6pnV'><tr id='W6pnV'><dt id='W6pnV'><q id='W6pnV'><span id='W6pnV'><b id='W6pnV'><form id='W6pnV'><ins id='W6pnV'></ins><ul id='W6pnV'></ul><sub id='W6pnV'></sub></form><legend id='W6pnV'></legend><bdo id='W6pnV'><pre id='W6pnV'><center id='W6pnV'></center></pre></bdo></b><th id='W6pnV'></th></span></q></dt></tr></i><div id='W6pnV'><tfoot id='W6pnV'></tfoot><dl id='W6pnV'><fieldset id='W6pnV'></fieldset></dl></div>
                      <tfoot id='W6pnV'></tfoot>

                      1. <legend id='W6pnV'><style id='W6pnV'><dir id='W6pnV'><q id='W6pnV'></q></dir></style></legend>

                        1. <small id='W6pnV'></small><noframes id='W6pnV'>