doufan3958 2019-02-22 06:51
浏览 95

Youtube Scraper与Php

I'm a rookie programmer, trying to find his footing in PHP and i currently want to build a You-tube scraper.

This scraper would search You-tube for a key word, say "drop shipping", and return a list of links bearing that keyword in their title.

so far this is what i got:

require('simple_html_dom.php');

$html = file_get_html("https://www.youtube.com/results?search_query=dropshipping");


$videos = [];
$i = 1;
foreach($html ->find("div.yt-lockup yt-lockup-tile yt-lockup-video vve-check clearfix") as $video){

      if($i > 10){
        break;
      }

      $videoDetails = $video0->find("a.yt-uix-tile-link yt-ui-ellipsis yt-ui-ellipsis-2 yt-uix-servicelink spf-link");
      $videoTitle = $videoDetails ->title;
      $videoUrl = "http://youtube.com" . $videoDetails->href;
   echo $videoUrl;

     $videos[] = [

    "title" => $videoTitle,
    "link" => $videoUrl


      ];
      $i++;

}

     echo(sizeof($videos));

?>

This keeps outputting zero(0). Can't figure out why this is. I suspect that the tag link changes every now and then coz i echoed the html page and analyzed the link, some times you'd have the link class to be "yt-uix-servicelink" other times it would be "yt-uix-sessionlink"

  • 写回答

1条回答 默认 最新

  • doulang1945 2019-02-22 07:05
    关注

    Scraping is (naturally) forbidden by YouTube terms.

    If you are interested in search itself, not implementing it by scraping specifically, you can look into using official API for it. Documentation for search:list has examples, including PHP one.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程