Ver Mensaje Individual
  #3 (permalink)  
Antiguo 10/10/2011, 00:32
LeandroA
 
Fecha de Ingreso: abril-2005
Mensajes: 351
Antigüedad: 19 años
Puntos: 3
Respuesta: Problema al obtener Html de una URL

Muchas gracias por su respuesta Triby, testie su código pero sigue sin funcionar, de echo no me esta arrojando ningún resultado.
Esto es lo que estoy haciendo.

Código PHP:
Ver original
  1. <?php
  2.  
  3. //--------------------------------------
  4. $url = "http://www.taringa.net/posts/reviews/12759660/Como-ver-Cuevana-en-HD-_Facil_.html#pagina-3";
  5.  
  6. $options[CURLOPT_URL] = $url;
  7. $options[CURLOPT_USERAGENT] = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1";
  8. $options[CURLOPT_FOLLOWLOCATION] = true;
  9. $options[CURLOPT_RETURNTRANSFER] = true;
  10. $data = sm_curl($options);
  11.  
  12. echo $data['response'];
  13. //--------------------------------------
  14.  
  15. function sm_curl($options){
  16.     // Hay que seguir redireccionamientos?
  17.     $follow = (isset($options[CURLOPT_FOLLOWLOCATION])) ? $options[CURLOPT_FOLLOWLOCATION] : false;
  18.  
  19.     // Instanciamos cURL
  20.     $go = curl_init();
  21.     $response = array();
  22.     if(ini_get('open_basedir') != '' || ini_get('safe_mode' == 'On') && $follow) {
  23.         // Aqui entramos solo si hay que seguir redireccionamientos y
  24.         // open_basedir o safe_mode estan activos
  25.  
  26.         // Eliminamos la opcion CURL para seguir redireccionamientos
  27.         unset($options[CURLOPT_FOLLOWLOCATION]);
  28.  
  29.         // Establecemos las opciones
  30.         curl_setopt_array($go, $options);
  31.  
  32.         // Ejecutamos y seguimos redireccionamientos
  33.         $response = curl_redir_exec($go);
  34.     } else {
  35.         curl_setopt_array($go, $options);
  36.         // Ejecutar
  37.         $response['response'] = curl_exec($go);
  38.         $response['headers'] = curl_getinfo($go);
  39.  
  40.         // Obtener errores
  41.         $response['errorNumber'] = curl_errno($go);
  42.         $response['errorMessage'] = curl_error($go);
  43.     }
  44.     curl_close($go);
  45.     return $response;
  46. }
  47.  
  48. // Seguir redireccionamientos con open_basedir o safe_mode = On
  49. function curl_redir_exec($ch) {
  50.     static $curl_loops = 0;
  51.     static $curl_max_loops = 20;
  52.     if ($curl_loops++>= $curl_max_loops) {
  53.         $curl_loops = 0;
  54.         return array('response' => '', 'headers' => '', 'errorNumber' => '47', 'errorMessage' => 'Too many redirects');
  55.     }
  56.     curl_setopt($ch, CURLOPT_HEADER, true);
  57.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  58.     $data = curl_exec($ch);
  59.     $data = str_replace("\n\r", "\n", $data);
  60.     list($header, $data) = explode("\n\n", $data);
  61.     $headers = curl_getinfo($ch);
  62.     $http_code = $headers['http_code'];
  63.     if ($http_code == 301 || $http_code == 302) {
  64.         $matches = array();
  65.         preg_match('/Location:(.*?)\n/', $header, $matches);
  66.         $url = @parse_url(trim(array_pop($matches)));
  67.         if (!$url) {
  68.             //couldn't process the url to redirect to
  69.             $curl_loops = 0;
  70.             return array('response' => '', 'headers' => '', 'errorNumber' => 3, 'errorMessage' => 'The URL was not properly formatted (redirect).');
  71.         }
  72.         $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
  73.         if (!$url['scheme'])
  74.             $url['scheme'] = $last_url['scheme'];
  75.         if (!$url['host'])
  76.             $url['host'] = $last_url['host'];
  77.         if (!$url['path'])
  78.             $url['path'] = $last_url['path'];
  79.         $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:'');
  80.         curl_setopt($ch, CURLOPT_URL, $new_url);
  81.         return curl_redir_exec($ch);
  82.     } else {
  83.         $curl_loops=0;
  84.         return array(
  85.             'response' => $data,
  86.             'headers' => $headers,
  87.             'errorNumber' => curl_errno($ch),
  88.             'errorMessage' => curl_error($ch),
  89.         );
  90.     }
  91. }
  92.  
  93. ?>


Espero pueda ayudarme, desde ya muchas gracias.

Saludos.
__________________
www.leandroascierto.com