Ver Mensaje Individual
  #3 (permalink)  
Antiguo 14/01/2013, 15:31
Avatar de Capimaster
Capimaster
 
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 9 meses
Puntos: 2
Respuesta: cuando getElementsByTagName esta vacia me da error

Extraer las noticias de este sitio http://www.notisistema.com/noticias/?x=0&y=0&s=ocotlan

Código PHP:
Ver original
  1. <script type="text/javascript" src="../dewplayer/swfobject.js"></script>
  2. <?php
  3. date_default_timezone_set('America/Mexico_City');
  4.  
  5. /**
  6.  * Clase para actuar como logger
  7.  *
  8.  * @author Christopher Valderrama
  9.  */
  10. class Logger {
  11.     private $handle;
  12.  
  13.     public function __construct($logFile, $append = false)
  14.     {
  15.         $mode = ($append) ? 'a' : 'w';
  16.         $this->handle = fopen($logFile, $mode);
  17.     }
  18.  
  19.     public function log($info)
  20.     {
  21.         $str = "[" . date("Y/m/d h:i:s", time()) . "] " . $info . "\r\n";
  22.         fwrite($this->handle, $str);
  23.     }
  24.  
  25.     public function __destruct()
  26.     {
  27.         fclose($this->handle);
  28.     }
  29. }
  30.  
  31. $log = new Logger('log.txt', true);
  32. $log->log('algo');
  33.  
  34.  
  35. $doc = new DOMDocument();
  36. $doc->loadHTMLFile('http://www.notisistema.com/noticias/?x=0&y=0&s=ocotlan');
  37. $xpath = new DOMXPath($doc);
  38. $peliculas = $xpath->query('//div[@class="post"]');
  39. ?>
  40. <div style="width:1200px;">
  41.  <?php
  42. for ($i = 0; $i < 6; $i++) {
  43.     $titulo = $peliculas->item($i)->getElementsByTagName('a')->item(0)->nodeValue;
  44.     $cuerpo = $peliculas->item($i)->getElementsByTagName('p')->item(1)->nodeValue;
  45.     $audio = $peliculas->item($i)->getElementsByTagName('audio')->item(0)->getAttribute('src');
  46.     echo "<div style='width:570px; margin:10px; height:340px; float:left; padding:5px; background:#cc092f;   -webkit-border-radius: 8px;    -moz-border-radius: 8px;    border-radius: 8px;'>";
  47.     echo "<div style='font-size:22px;'>".utf8_decode($titulo)."</div>";
  48.     echo '<div id="dewplayer_content">
  49.                 <object data="../dewplayer/dewplayer.swf" width="200" height="20" name="dewplayer" id="dewplayer" type="application/x-shockwave-flash">
  50.                 <param name="movie" value="dewplayer.swf" />
  51.                 <param name="flashvars" value="mp3='.$audio.'" />
  52.                 <param name="wmode" value="transparent" />
  53.                 </object>
  54.             </div>';
  55.     echo "<p><div style='width:565px; color:#23fbe4; font-size:18px;'>".utf8_decode($cuerpo)."</div></p>";
  56.     echo "<div class='clear'></div>";
  57.     echo "</div>";
  58.  }
  59. ?>
  60. </div>
  61. <div style="clear:both;"></div>
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México