Foros del Web » Programando para Internet » PHP »

extraer texto de pagina html

Estas en el tema de extraer texto de pagina html en el foro de PHP en Foros del Web. Tengo este html Código PHP: < div align = "center"  class= "ensbustertitle" > INDICES </ div >                 </ td >               </ tr >               < tr > ...
  #1 (permalink)  
Antiguo 02/10/2007, 12:45
Avatar de Gerald  
Fecha de Ingreso: julio-2003
Mensajes: 1.356
Antigüedad: 20 años, 10 meses
Puntos: 2
extraer texto de pagina html

Tengo este html
Código PHP:
<div align="center" class="ensbustertitle">INDICES</div>
                </
td>
              </
tr>
              <
tr>
                <
td>
                  <
table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <
tr height=20>
                      <
td class="ensbustertitle" width="25%">
                        <
div align="left">&nbsp;&nbsp;&nbsp;&nbsp;IGBVL</div>
                      </
td>
                      <
td width="25%" bgcolor="#FF9900">
                        <
div align="center" class="ensbustermenu">-0.88</div>
                      </
td>
                      <
td class="ensbustertitle" width="25%">
                        <
div align="center">ISBVL</div>
                      </
td>
                      <
td width="25%" bgcolor="#FF9900">
                        <
div align="center" class="ensbustermenu">-0.65</div>
                      </
td>
                    </
tr
Del cual yo quiero extraer lo que esta en
<div align="center" class="ensbustermenu">-0.88</div>

Estuve chequeando y he llegado hasta aqui
http://www.desarrolloweb.com/faq/ext...ozo-texto.html
Ese html está en otro dominio, y no me ubico por como lograr mi cometido de lograr extraer ese texto.
Que me recomiendan?

Saludos
__________________
Solo por Hoy: Trataré de fortalecer mi mente. Estudiaré y aprenderé algo útil
Hoteldipity
Arte Caracol
  #2 (permalink)  
Antiguo 02/10/2007, 22:59
Avatar de Gerald  
Fecha de Ingreso: julio-2003
Mensajes: 1.356
Antigüedad: 20 años, 10 meses
Puntos: 2
Re: extraer texto de pagina html

Encontre este pedazo de codigo en www.php.net/file

Código PHP:
<?php
// Obtiene un archivo en una matriz. En este ejemplo usaremos HTTP
// para obtener el codigo fuente HTML de una URL.

$lineas file('http://www.example.com/');

// Recorrer nuestra matriz, mostrar el codigo HTML como codigo fuente
// HTML, y los numeros de linea tambien.
foreach ($lineas as $linea_num => $linea) {
    echo 
"L&iacute;nea #<b>{$linea_num}</b> : " htmlspecialchars($linea) . "<br />\n";
}

// Otro ejemplo, obtengames una pagina web como una cadena. Vea
// tambien file_get_contents().
$html implode(''file('http://www.example.com/'));
?>
Y aplicando a mi codigo obtengo esto
Código PHP:
<div align="center" class="ensbustertitle">INDICES</div>
                </
td>
              </
tr>
              <
tr>
                <
td>
                  <
table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <
tr height=20>
                      <
td class="ensbustertitle" width="25%">
                        <
div align="left">&nbsp;&nbsp;&nbsp;&nbsp;IGBVL</div>
                      </
td>
                      <
td width="25%" bgcolor="#FF9900">
                        <
div align="center" class="ensbustermenu">-0.88</div>
                      </
td>
                      <
td class="ensbustertitle" width="25%">
                        <
div align="center">ISBVL</div>
                      </
td>
                      <
td width="25%" bgcolor="#FF9900">
                        <
div align="center" class="ensbustermenu">-0.65</div>
                      </
td>
                    </
tr
Y quiero sacar los valores :
<div align="center" class="ensbustermenu">-0.88</div>
<div align="center" class="ensbustermenu">-0.65</div>

Seguire indagando
Saludos
__________________
Solo por Hoy: Trataré de fortalecer mi mente. Estudiaré y aprenderé algo útil
Hoteldipity
Arte Caracol
  #3 (permalink)  
Antiguo 03/10/2007, 00:03
Avatar de Gerald  
Fecha de Ingreso: julio-2003
Mensajes: 1.356
Antigüedad: 20 años, 10 meses
Puntos: 2
Re: extraer texto de pagina html

Código PHP:
<?php

$url 
'datos.html';

// Obtengo el contenido de la web
$text file_get_contents($url);
//function to get a substring between between two other substrings

function substring_between($haystack,$start,$end) {
    if (
strpos($haystack,$start) === false || strpos($haystack,$end) === false) {
        return 
false;
    } else {
        
$start_position strpos($haystack,$start)+strlen($start);
        
$end_position strpos($haystack,$end);
        return 
substr($haystack,$start_position,$end_position-$start_position);
    }
}

$text htmlspecialchars($text);
$title substring_between($text,'&lt;title&gt;','&lt;/title&gt;');
echo 
$title;
?>
Por ahora tengo esto y me imprime lo que esta en <title></title> pero al querer lo que esta en <div align="center" class="ensbustermenu">-0.88</div> no me imprime nada.
Que estoy haciendo mal?
__________________
Solo por Hoy: Trataré de fortalecer mi mente. Estudiaré y aprenderé algo útil
Hoteldipity
Arte Caracol
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 06:04.