Ver Mensaje Individual
  #10 (permalink)  
Antiguo 21/10/2012, 22:04
Avatar de xarmagedonx
xarmagedonx
 
Fecha de Ingreso: marzo-2009
Mensajes: 360
Antigüedad: 15 años, 11 meses
Puntos: 29
Respuesta: Problema con codigo PHP, no encuentro el error

Bueno te dejo el código (son unas 60 lineas):
Código PHP:
Ver original
  1. //Aca arriba se encuentran algunas variables definidas junto con la funcion storelink
  2. function extraer($url, $prof){
  3. $server_link = mysql_connect("aca", "se", "conecta");
  4.  
  5. if(!$server_link){ die("Falló la Conexión ". mysql_error());
  6. }
  7. $db_selected = mysql_select_db("BD", $server_link);
  8. if(!$db_selected){ die("No se pudo seleccionar la Base de Datos ". mysql_error());
  9. }
  10.  
  11. $url = "no";
  12. $patron = "funciona";
  13. $prof = 1;
  14. $userAgent = 'buuuu';
  15. $ch = curl_init();
  16. curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
  17. curl_setopt($ch, CURLOPT_URL,$url);
  18. curl_setopt($ch, CURLOPT_HTTPHEADER, array(("Accept-Language: es-es,en")));
  19. curl_setopt($ch, CURLOPT_FAILONERROR, true);
  20. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  21. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  22. curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
  23. curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
  25. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  26. $html= curl_exec($ch);
  27. //Aca viene lo peor:
  28. if (!$html) {
  29.     echo "<br />cURL error number:" .curl_errno($ch);
  30.     echo "<br />cURL error:" . curl_error($ch);
  31.     exit;
  32. }
  33. //Si el código quisiera funcionar me haría muy feliz jajajaj
  34.  
  35. $dom = new DOMDocument();
  36. @$dom->loadHTML($html);
  37.  
  38. $xpath = new DOMXPath($dom);
  39. $hrefs = $xpath->evaluate("/html/body//a");
  40.  
  41. if($prof < 2 and mysql_num_rows($busqueda)==0 and strpos($url, $patron)!==FALSE){
  42.     $busqueda = mysql_query("SELECT webUrl FROM webs WHERE webUrl='$url'");
  43.     preg_match_all ("(<title>(.*)<\/title>)siU", $html, $title);
  44.     preg_match_all ("(<meta name=\"description\" content=\"(.*)\"\/>)siU", $html, $description);
  45.     preg_match_all ("(<meta name=\"keywords\" content=\"(.*)\"\/>)siU", $html, $keys);
  46.     $titulo = $title[1][0];
  47.     $descripcion = $description[1][0];
  48.     $keywords = $keys[1][0];
  49.     storeLink($titulo,$descripcion,$url,$keywords);
  50.     }
  51. for ($i = 0; $i < $hrefs->length; $i++) {
  52.     $href = $hrefs->item($i);
  53.     $url2 = $href->getAttribute('href');
  54.     extraer($url2, $prof ++);
  55. }
  56. }
  57. extraer($url, $prof);
  58. //FIN

Bueno, muchas gracias por todo, espero tu sentencia

PD: Volví a añadirle la @ al DOM, porque los errores que me muestra son del html de las páginas, para esto estoy viendo como utilizar tiny.