开发者

How can I grep YouTube video ID from the web?

I was wondering if it was possible to get all the video IDs from a YouTube playlist pages and display them in a list. 开发者_开发知识库

<li class="playlist-video-item odd">
    <a href="/watch?v=oHg5SJYRHA0&amp;list=FLk8PLezsTU6MuuBxE5utNQw&amp;index=3" class="tile-link-block video-tile">
      <span class="video-index">3</span>

        <span class="playlist-video-item-base-content">
  <span class="thumb-container">
<span class="ux-thumb-wrap">
    <span class="video-thumb ux-thumb-114 "><span class="clip"><img src="//i2.ytimg.com/vi/eVMWgmQA4Ig/default.jpg" alt="Thumbnail" ></span></span>
    <span class="video-time">3:37</span>
    <button type="button" class="addto-container addto-button short video-actions yt-uix-button yt-uix-button-short" onclick=";return false;" data-button-menu-id="shared-addto-menu" data-video-ids="oHg5SJYRHA0" data-button-action="yt.www.addtomenu.load" data-feature="thumbnail" role="button"><img class="yt-uix-button-icon yt-uix-button-icon-addto" src="//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif" alt=""><span class="yt-uix-button-content"><span class="addto-label hid">Add to</span></span><img class="yt-uix-button-arrow" src="//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif" alt=""></button>
</span>

As you can see the ID is here data-video-ids="oHg5SJYRHA0"


Rather than scraping the IDs from markup like that, you should probably take a look at the YouTube API


I guess you want this to be done with jQuery, according to your tags.

$('span.ux-thumb-wrap button').data('video-ids')

Your example code only have one ID, so I wouldn't know how to create a list. Or what type of list for that matter. Please add a comment with further instrux as needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜