-1

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"

Quintin
  • 11
  • 2
  • 2
    Welcome to stackoverflow. This is not a coding service website. Tried it by your own and show us, what you have done so far in a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and you'll get help – gehbiszumeis Feb 22 '19 at 07:01
  • 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](https://developers.google.com/youtube/v3/docs/search/list) has examples, including PHP one. – Rarst Feb 22 '19 at 07:05

1 Answers1

3

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.

Rarst
  • 2,255
  • 16
  • 25