Foros del Web » Programando para Internet » PHP »

Curl en php

Estas en el tema de Curl en php en el foro de PHP en Foros del Web. con este codigo accedo a las propiedades al codigo e una web, pero como puedo hacer para cargar un tag de esa web (por ejemplo ...
  #1 (permalink)  
Antiguo 04/08/2011, 12:17
Avatar de diegovazgonz  
Fecha de Ingreso: octubre-2010
Ubicación: Ourense
Mensajes: 184
Antigüedad: 13 años, 6 meses
Puntos: 11
Curl en php

con este codigo accedo a las propiedades al codigo e una web, pero como puedo hacer para cargar un tag de esa web (por ejemplo el title)
Código PHP:
Ver original
  1. <?php
  2. $curl = curl_init();
  3. curl_setopt($curl, CURLOPT_URL,
  4.     'http://www.google.es/');
  5. curl_setopt($curl, CURLOPT_HEADER, 0); //no mostrar cabeceras
  6. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //no mostrar en pantalla
  7. $data = curl_exec($curl); //descargar página
  8. curl_close($curl);
  9. ?>
__________________
El mejor vino Ribeiro http://www.pedeperdiz.com
  #2 (permalink)  
Antiguo 04/08/2011, 12:36
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: Curl en php

Podrías usar DOM o SimpleXML para tomar la etiquetas que quieras.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #3 (permalink)  
Antiguo 04/08/2011, 12:50
Avatar de diegovazgonz  
Fecha de Ingreso: octubre-2010
Ubicación: Ourense
Mensajes: 184
Antigüedad: 13 años, 6 meses
Puntos: 11
Respuesta: Curl en php

lo e intentado pero no me premite utilizar el dom
__________________
El mejor vino Ribeiro http://www.pedeperdiz.com
  #4 (permalink)  
Antiguo 04/08/2011, 12:52
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: Curl en php

¿Por qué no te permite usar DOM?
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #5 (permalink)  
Antiguo 04/08/2011, 13:06
Avatar de diegovazgonz  
Fecha de Ingreso: octubre-2010
Ubicación: Ourense
Mensajes: 184
Antigüedad: 13 años, 6 meses
Puntos: 11
Respuesta: Curl en php

como seria el ejemplo a lo mejor lo pongo mal?
__________________
El mejor vino Ribeiro http://www.pedeperdiz.com
  #6 (permalink)  
Antiguo 04/08/2011, 13:23
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: Curl en php

Pero es más fácil si muestras lo que haz hecho, pero es facil algo como
Código PHP:
Ver original
  1. <?php
  2. $dom = new DOMDocument();
  3. @$dom->loadHTML(file_get_contents('http://forosdelweb.com/'));
  4. $list = $dom->getElementsByTagName("title");
  5. if ($list->length > 0) {
  6.     echo $list->item(0)->textContent;
  7. }
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #7 (permalink)  
Antiguo 04/08/2011, 13:56
Avatar de diegovazgonz  
Fecha de Ingreso: octubre-2010
Ubicación: Ourense
Mensajes: 184
Antigüedad: 13 años, 6 meses
Puntos: 11
Respuesta: Curl en php

con esto
Código PHP:
Ver original
  1. <?php
  2. $curl = curl_init();
  3. curl_setopt($curl, CURLOPT_URL,
  4.     'http://www.google.es/');
  5. curl_setopt($curl, CURLOPT_HEADER, 0); //no mostrar cabeceras
  6. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //no mostrar en pantalla
  7. $data = curl_exec($curl); //descargar página
  8. $dom = new DOMDocument();
  9. $dom->loadHTML($data);
  10. $list = $dom->getElementsByTagName("title");
  11. if ($list->length > 0) {
  12.     echo $list->item(0)->textContent;
  13. }
  14. curl_close($curl);
  15. ?>
me da esto
Código HTML:
Ver original
  1. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  2.  
  3. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  4.  
  5. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  6.  
  7. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  8.  
  9. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  10.  
  11. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  12.  
  13. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  14.  
  15. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  16.  
  17. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  18.  
  19. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  20.  
  21. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  22.  
  23. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  24.  
  25. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  26.  
  27. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  28.  
  29. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  30.  
  31. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  32.  
  33. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  34.  
  35. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  36.  
  37. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  38.  
  39. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  40.  
  41. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  42.  
  43. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  44.  
  45. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  46.  
  47. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  48.  
  49. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  50.  
  51. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  52.  
  53. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  54.  
  55. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  56.  
  57. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  58.  
  59. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  60.  
  61. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Attribute onclick redefined in Entity, line: 28 in mi web/index.php on line 9
  62.  
  63. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  64.  
  65. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  66.  
  67. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  68.  
  69. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  70.  
  71. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  72.  
  73. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  74.  
  75. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: no name in Entity, line: 28 in mi web/index.php on line 9
  76.  
  77. Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 28 in mi web/index.php on line 9
  78. Google
__________________
El mejor vino Ribeiro http://www.pedeperdiz.com
  #8 (permalink)  
Antiguo 04/08/2011, 13:57
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: Curl en php

Por eso coloqué el simbolo de @ en $dom->loadHTML($data); porque DOM no va a poder interpretar correctamente ese código, porque hay algunas etiquetas que no las va a interpretar correctamente. Pero si te fijas al final te da el resultado que quisiste buscar.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #9 (permalink)  
Antiguo 04/08/2011, 13:59
Avatar de diegovazgonz  
Fecha de Ingreso: octubre-2010
Ubicación: Ourense
Mensajes: 184
Antigüedad: 13 años, 6 meses
Puntos: 11
Respuesta: Curl en php

muchisimas gracias amigo, espero que te pueda ayudar en algo
__________________
El mejor vino Ribeiro http://www.pedeperdiz.com
  #10 (permalink)  
Antiguo 04/08/2011, 14:07
Avatar de diegovazgonz  
Fecha de Ingreso: octubre-2010
Ubicación: Ourense
Mensajes: 184
Antigüedad: 13 años, 6 meses
Puntos: 11
Respuesta: Curl en php

una cosa amigo, si utilizo el tag script falla
__________________
El mejor vino Ribeiro http://www.pedeperdiz.com
  #11 (permalink)  
Antiguo 04/08/2011, 14:08
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: Curl en php

Trata y nos dejas saber.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos

Etiquetas: curl
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:59.