0

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
  • 21
  • 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

2 Answers2

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,335
  • 16
  • 26
0

Youtube pages are loaded dynamically .. not static .. thats why scraping YouTube will not work .. use Search:list with a YouTube key instead like the other guy said .. there's alot of tutorials on it

Drek M.
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 02 '22 at 06:17