Weyne

CURL PHP

Mar 12th, 2017
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. <?php
  2.     $ch = curl_init();
  3.     curl_setopt($ch, CURLOPT_URL, 'https://www.youtube.com/weyne');
  4.     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1');
  5.     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language: es-es,en"));
  6.     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  7.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  8.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  9.    
  10.    
  11.    
  12.     $result = curl_exec($ch);
  13.    
  14.     if(!$result)
  15.     {
  16.         echo "Error: " . curl_error($ch) . " Code: " . curl_errno($ch) . "<br/>";
  17.     }
  18.    
  19.     curl_close($ch);
  20.    
  21.     //busqueda por patrones para obtener el número de suscriptores
  22.     preg_match_all("(<span class=\"yt-subscription-button-subscriber-count-branded-horizontal subscribed yt-uix-tooltip\" title=\"(.*)\")siU", $result, $matches1);
  23.    
  24.     $suscriptores = $matches1[1][0];
  25.    
  26.    
  27.     echo "Suscriptores: " . $suscriptores;
  28.  
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment