Foros del Web » Programando para Internet » PHP »

Crear Robot de autogestion

Estas en el tema de Crear Robot de autogestion en el foro de PHP en Foros del Web. Buenas tardes foro, me pregunto si habria alguna forma de crear un robot (script) q haga la siguiente tarea, q busque en una o unas ...
  #1 (permalink)  
Antiguo 10/05/2005, 11:47
 
Fecha de Ingreso: noviembre-2003
Ubicación: Frente a la PC
Mensajes: 120
Antigüedad: 20 años, 5 meses
Puntos: 0
Crear Robot de autogestion

Buenas tardes foro, me pregunto si habria alguna forma de crear un robot (script) q haga la siguiente tarea, q busque en una o unas direcciones web, en alguna parte de la pagina donde haya por ejemplo una noticia, entonces el tomara el titular de la noticia y lo guarda en una base de datos para despues mostrarlo en otra pagina y q tambien recoja el link hacia la noticia completa y la coloque como link de su respectivo titulo, Me he hecho explicar bien?

Gracias..
__________________
Sin sombra no hay luz...
  #2 (permalink)  
Antiguo 10/05/2005, 12:27
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Tu ya tienes claro el "patrón" de busqueda para localizar esa "noticia" en tal página? ..

Es decir . primero debes partir por definir viendo el código fuente de esa página .. por "donde" queda ese titular de noticia y las noticias .. Además de pedir permiso al autor de la misma.

En su defecto .. ya que hablas de "noticias" mejor será que busques noticias en formato RSS (derivado de XML) que hoy por hoy casi toda fuente de noticias las proporciona en ese formato. El "RSS" lo "parseas" (lees y le das formato) conforme tu diseño de tu sitio lo requiera .. en un proceso "limpio" .. pues ese formato de "Archivo" define bien claro que es el título de la noticia/artículo .. la noticia .. el autor .. fechas .. etc ..

Un saludo,
  #3 (permalink)  
Antiguo 10/05/2005, 13:35
 
Fecha de Ingreso: noviembre-2003
Ubicación: Frente a la PC
Mensajes: 120
Antigüedad: 20 años, 5 meses
Puntos: 0
listo Cluster, ya tengo de donde sacar ese formato ahora, como lo leo, integro y saco en php?
__________________
Sin sombra no hay luz...
  #4 (permalink)  
Antiguo 10/05/2005, 14:28
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Pues si ya tienes el URL de tu "RSS" donde obtener esos datos (tus noticias) .. tan sólo busca algún "parse RSS" en PHP .. usa google .. salen muchos (o buscalo directamente en sitios como www.phpclasses.org).

Un saludo,
  #5 (permalink)  
Antiguo 11/05/2005, 08:55
 
Fecha de Ingreso: noviembre-2003
Ubicación: Frente a la PC
Mensajes: 120
Antigüedad: 20 años, 5 meses
Puntos: 0
ya tengo todo cluster, ahora lo q quisiera q me ayudaras es el lo siguiente:
el script q consegui originalmente muestra todo ,osea, el titulo y el contenido completo de la noticia, lo unico q quiero es q muestre solo los titulares, ya lo modifique y logre q solo muestre los titulares pero ahora el problema y ahi si no se como hacerle hasta ahora es q me deje por lo menos una linea entre titular y titular y poder restringir el numero de tutilares a mostrar, osea, no los quiero mostrar todos porq son demasiados y descuadraria la página...
En mi archivo donde quiero mostrar estas noticias hago un include de la siguiente manera:

Inicio.php
Código PHP:
<?php
include_once("XmlParser.class.php");
$FeedUrl="http://www.rnv.gov.ve/noticias/index.php?act=ShowRSS";
$XMLpar = new SimpleXmlParser($FeedUrl);
?>
El archivo q estoy incluyendo es XmlParser.class.php

Código PHP:
<?php
      
class SimpleXmlParser{
             
// @ Variable Holding Parser
    
var $SimpleParser;

    
//@ Feed Source URL
    
var $feedUrl;

    
//@ Variables to Hold the Data
    
var $title "";
    var 
$description "";
    var 
$link "";
    var 
$author="";
    var 
$pubDate="";
    var 
$insideitem false;
    var 
$tag "";


    
// Purpose : Constructor, Which will initialize the XML Parser
    
function SimpleXmlParser($MyFeed){
        
//To begin, I create an instance of the XML parser
        
$this->SimpleParser xml_parser_create();   // creates a new XML parser and returns a reousurce handle referencing 
        
        
$this->feedUrl=$MyFeed;    // Assigns the Feed Source to the Member Variable
        
        
xml_set_object($this->SimpleParser,&$this);      // allows to use parser inside object
        
xml_set_element_handler($this->SimpleParser"XmlParserFirstElement""XmlParserendElement");      // Sets the element handler functions for the XML parser parser
        
xml_set_character_data_handler($this->SimpleParser"characterData");   // Sets the character data handler function for the XML parser parser        
        
        
$this->ParseFeed();   // Call to Parser Function
    
}
    
    function 
XmlParserFirstElement($parser$tagName$attrs) {
        
//The Function Will be called, when ever the XML_PARSER Encounters a start Tag, in the XML File
        
if ($this->insideitem) {
            
$this->tag $tagName;
        } elseif (
$tagName == "ITEM") {
            
$this->insideitem true;
        }
    }

    function 
XmlParserendElement($parser$tagName) {
        
//The Function Will be called, when ever the XML_PARSER Encounters a end Tag, in the XML File
        
if ($tagName == "ITEM") {
              
printf("<dt><b><a href='%s'>%s</a></b></dt>",
            
trim($this->link),htmlspecialchars(trim($this->title)));    //Display the Title Element from the XML file to HTML
            // Description element is made to display in HTML. AQUI LE ELIMINE EL CONTENIDO
            // Deallocation of all Global Variables
            
$this->title ""
            
$this->description "";
            
$this->link "";
            
$this->insideitem false;
        }
    }    
    
    
//Function will be called by the Parser when the end tage of the element is processed. Requires Two Permeters
    
function characterData($parser$data) {
        
//Permeters: the parser instance and the string containing the data.
        
if ($this->insideitem) {
            switch (
$this->tag) {
                case 
"TITLE":
                
$this->title .= $data;
                break;
                case 
"DESCRIPTION":
                
$this->description .= $data;
                break;
                case 
"LINK":
                
$this->link .= $data;
                break;
            }
        }
    }

    function 
ParseFeed(){
        
// This is the Place we need to Do error Handling for the XML file, which is not done in this class
        
$fp fopen($this->feedUrl,"r")       // Open the XML file for reading.
            
or die("Oops!!! Unexpected Error While Reading the Feed");   // This part will be executed when we compiler is Unable to Open the XML Feed
        //Starts reading the contents of the file, 4K at a time, and put it in the variable “$data”
        
while ($data fread($fp4096)){
            
xml_parse($this->SimpleParser$datafeof($fp));
        }
        
//Perform Some Clean Up Work Before Closing the File.
        //Closing the XML File
        
fclose($fp);
        
//Release the XML Parser
        
xml_parser_free($this->SimpleParser);
    }
}    
?>

Gracias..
__________________
Sin sombra no hay luz...
  #6 (permalink)  
Antiguo 11/05/2005, 14:47
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
De donde tomastes el código no tienes ejemplos?

Bueno .. no me he puesto a practicar con ese ejemplo ... Pero si vas modifcandola quitando cosas . mm lo mejor es que crees tu método nuevo que te devuelva lo que quieras.

A todo esto .. que formato usas concretamente de esas noticas: XML? .. RSS? (Versión) .. cual? ...

Te lo comento por qué un "parser" de XML genérico puede servirte para leer un RSS (que es un derivado de XML con elementos particulares bien definidos) .. pero uno de RSS por ejemplo exclusivo te irá mejor si es así.

Un saludo,
  #7 (permalink)  
Antiguo 17/05/2005, 23:00
 
Fecha de Ingreso: abril-2003
Mensajes: 587
Antigüedad: 21 años
Puntos: 5
tengo un problema con esta clase que los acentos y demas me los saca con simbolos ejemplo:

Protected: ¿Importa el tamaño?

asi me saca los articulos.
¿que ocurre?
__________________
Si la vida te da la espalda tocale el culo
  #8 (permalink)  
Antiguo 18/05/2005, 02:22
 
Fecha de Ingreso: enero-2004
Ubicación: Salto
Mensajes: 484
Antigüedad: 20 años, 3 meses
Puntos: 2
Podrías usar las funciones de urlencode, urldecode
http://ar2.php.net/manual/es/ref.url.php
Saludos cuidate
__________________
Dios dira que esto no es justo, pero lo sera...
  #9 (permalink)  
Antiguo 18/05/2005, 12:16
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Revisa la función:

utf8_decode()
http://www.php.net/utf8_decode

Un saludo,
  #10 (permalink)  
Antiguo 18/05/2005, 16:25
Avatar de alexis77  
Fecha de Ingreso: diciembre-2003
Mensajes: 119
Antigüedad: 20 años, 4 meses
Puntos: 0
josecarbono interesante el script ojala que puedas solucionar el problea que tienes
  #11 (permalink)  
Antiguo 18/05/2005, 20:28
 
Fecha de Ingreso: noviembre-2003
Ubicación: Frente a la PC
Mensajes: 120
Antigüedad: 20 años, 5 meses
Puntos: 0
Listo! bueno, casi.. ahora hay otra variante..


Esto lo coloco al inicio del documento..
Código PHP:
<?php
$itemNum
=0;
class 
RSSParser    {
    var 
$channel_title="";
    var 
$channel_website="";
    var 
$channel_description="";
    var 
$channel_pubDate="";
    var 
$channel_lastUpdated="";
    var 
$channel_copyright="";
    var 
$title="";
    var 
$link="";
    var 
$description="";
    var 
$pubDate="";
    var 
$author="";
    var 
$url="";
    var 
$width="";
    var 
$height="";
    var 
$inside_tag=false;    
    function 
RSSParser($file)    {
            
$this->xml_parser xml_parser_create();
            
xml_set_object$this->xml_parser, &$this );
            
xml_set_element_handler$this->xml_parser"startElement""endElement" );
            
xml_set_character_data_handler$this->xml_parser"characterData" );
            
$fp = @fopen("$file","r") or die( "$file could not be opened" );
            while (
$data fread($fp4096)){xml_parse$this->xml_parser$datafeof($fp)) or die( "XML error");}
            
fclose($fp);
            
xml_parser_free$this->xml_parser );
        }
    
    function 
startElement($parser,$tag,$attributes=''){
        
$this->current_tag=$tag;
        if(
$this->current_tag=="ITEM" || $this->current_tag=="IMAGE"){
            
$this->inside_tag=true;
            
$this->description="";
            
$this->link="";
            
$this->title="";
            
$this->pubDate="";
        }
    }
    
    function 
endElement($parser$tag){
        switch(
$tag){
            case 
"ITEM":
                
$this->titles[]=trim($this->title);
                
$this->links[]=trim($this->link);
                
$this->descriptions[]=trim($this->description);
                
$this->pubDates[]=trim($this->pubDate);
                
$this->authors[]=trim($this->author);
                
$this->author=""$this->inside_tag=false;
                break;
            case 
"IMAGE":
                
$this->channel_image="<img src=\"".trim($this->url)."\" width=\"".trim($this->width)."\" height=\"".trim($this->height)."\" alt=\"".trim($this->title)."\" border=\"0\" title=\"".trim($this->title)."\" />";
                
$this->title=""$this->inside_tag=false;
            default:
                break;
        }
    }
    
    function 
characterData($parser,$data){
        if(
$this->inside_tag){
            switch(
$this->current_tag){
                case 
"TITLE":
                    
$this->title.=$data; break;
                case 
"DESCRIPTION":
                    
$this->description.=$data; break;
                case 
"LINK":
                    
$this->link.=$data; break;
                case 
"URL":
                    
$this->url.=$data; break;                    
                case 
"WIDTH":
                    
$this->width.=$data; break;
                case 
"HEIGHT":
                    
$this->height.=$data; break;
                case 
"PUBDATE":
                    
$this->pubDate.=$data; break;
                case 
"AUTHOR":
                    
$this->author.=$data;    break;
                default: break;                                    
            }
//end switch
        
}else{
            switch(
$this->current_tag){
                case 
"DESCRIPTION":
                    
$this->channel_description.=$data; break;
                case 
"TITLE":
                    
$this->channel_title.=$data; break;
                case 
"LINK":
                    
$this->channel_website.=$data; break;
                case 
"COPYRIGHT":
                    
$this->channel_copyright.=$data; break;
                case 
"PUBDATE":
                    
$this->channel_pubDate.=$data; break;                    
                case 
"LASTBUILDDATE":
                    
$this->channel_lastUpdated.=$data; break;                
                default:
                    break;
            }
        }
    }
}

$nacionales = new RSSParser("http://www.rnv.gov.ve/noticias/index.php?act=ShowRSS");
?>
Le coloco el numero de titulares q uiero mostrar, en este caso 10..

Código PHP:
<?php
$nacionales_RSSmax
=10;
if(
$nacionales_RSSmax==|| $nacionales_RSSmax>count($nacionales->titles))$nacionales_RSSmax=count($nacionales->titles);
for(
$itemNum=0;$itemNum<$nacionales_RSSmax;$itemNum++){?> //Aqui empieza la region q quiero repetir, ya sea una celda o una tabla o simplemente los titulos..
Y aqui muestro mis noticias y les hago el link..

Código PHP:
 <a href="<?php echo $nacionales->links[$itemNum]; ?>" target="_blank" class="titulres"><?php echo $nacionales->titles[$itemNum]; ?></a>

Termina la region q este repitiendo..

Código PHP:
<?php ?>
y listo!

El siguiente problema o mejor dicho, el siguiente reto es como hacer para separar y seleccionar el numero de titulares q quiero por categoria, por ejemplo, solo quiero mostra tres titulares de la categoria Deportes y luego tres de la categoria Titulares y luego tres de la categoria Internacionales y asi con cualquier categoria..

Bueno, a ver como se logra..

Saludos..
__________________
Sin sombra no hay luz...
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 01:40.