Como puedo modificar este codigo?

  • Autor Autor cfelipe
  • Fecha de inicio Fecha de inicio
Hola amigo, usa este código:

Insertar CODE, HTML o PHP:
<?php


$app = $_GET['app'];
$dom = new DOMDocument();
try{
      $opts = array(
        'http'=>array(
            'method'=>"GET",
            'header'=>"Accept-language: es\r\n" .
                          "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n"
        )
      );
      $context = stream_context_create($opts);
      $html = file_get_contents('https://play.google.com/store/apps/details?id=' . $app,false,$context);
      @$dom->loadHTML($html);
}catch(Exception $e){
      echo 'Error: ' . $e->getMessage();
      header('HTTP/1.0 404 Not Found');
}
$a = $dom->getElementsByTagName('div');
$nodes = array();
for ($i = 0; $i < $a->length; $i++) {
      $attr = $a->item($i)->getAttribute('itemprop');
      $nodes[$attr] = $a->item($i)->textContent;
}
if(count($nodes) == 0){
      header('HTTP/1.0 404 Not Found');
}
?>

<ul>
    <li><b>Nombre:</b> <?php echo $nodes['name']; ?></li>
    <li><b>Actualizado:</b> <?php echo $nodes['datePublished']; ?></li>
    <li><b>Versión de software:</b> <?php echo $nodes['softwareVersion']; ?></li>
    <li><b>Requiere android:</b> <?php echo $nodes['operatingSystems']; ?></li>
</ul>



Le mostrará algo como esto:

e33dd7ca5f5943cd94fe7a22e3c7b9ba.png


Si quiere agregar más datos, haga var_dump() a la variable $nodes.

Saludos.
 
muchas gracias me salvaste la vidaa!!!! y para obtener las imagenes? como seria
 
Para las imágenes agrega esto:

PHP:
<?php
//Obtener elementos con tag img
$tagimg = $dom->getElementsByTagName('img');
$imagenes = array();
for ($i = 0; $i < $tagimg->length; $i++) {
      $itemprop = $tagimg->item($i)->getAttribute('itemprop');
      $src = $tagimg->item($i)->getAttribute('src');

       //Se filtran solo las imagenes que sean screenshot de la aplicacion
       if ($itemprop != 'screenshot') {
          continue;
      }
      $imagenes[$i] = $src;
}
if(count($imagenes) == 0){
      echo 'No hay imagenes que mostrar';
}

//Mostrar imagenes
foreach ($imagenes as $img => $src) {
  echo "<img src=\"".$src."\" width=\"150px\">";
}

Saludos compañero.
 
Atrás
Arriba