Foros del Web » Programando para Internet » PHP »

un spider/robot como este pero en php

Estas en el tema de un spider/robot como este pero en php en el foro de PHP en Foros del Web. hace un tiempo hice este codigo en asp que hace un poco como un spider: Código: <% Function GetHTML(strURL) Dim objXMLHTTP, strReturn, strHTML Set objXMLHTTP ...
  #1 (permalink)  
Antiguo 24/01/2006, 09:49
 
Fecha de Ingreso: enero-2002
Mensajes: 1.438
Antigüedad: 22 años, 3 meses
Puntos: 0
un spider/robot como este pero en php

hace un tiempo hice este codigo en asp que hace un poco como un spider:

Código:
<%

Function GetHTML(strURL) 
Dim objXMLHTTP, strReturn, strHTML
Set objXMLHTTP = SErver.CreateObject("MSXML2.ServerXMLHTTP")
objXMLHTTP.Open "GET", strURL, False
objXMLHTTP.setRequestHeader "Accept-Language", "sp"
objXMLHTTP.setRequestHeader "Pragma", "no-cache"
objXMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objXMLHTTP.SetRequestHeader "Content-Type", "text/html"
objXMLHTTP.SetRequestHeader "charset", "iso-8859-1" 
objXMLHTTP.Send
if objXMLHTTP.statusText="OK" then
body8209 = objXMLHTTP.responseBody
GetHTML = ""
For i = 0 to UBound(body8209)
GetHTML = GetHTML & chrw(ascw(chr(ascb(midb(body8209,i+1,1)))))
Next 
else
Response.write "Error en página:" & objXMLHTTP.statustext
end if
Set objXMLHTTP = Nothing
End Function

 
  Function GetText(strText, strStartTag, strEndTag)
    dim intStart
    intStart = instr(1, strText, strStartTag, vbtextcompare)
    if intStart then
	  intStart = intStart + len(strStartTag)
	  intEnd = InStr(intStart + 1,strText,strEndTag,vbtextcompare)
	  GetText = CStr(Mid(strText,intStart,intEnd - intStart))
    else
	  GetText = " " 
    end if
  End Function
%>
y se se puede llamar con

Código:
MM_URL = "http://www.forosdelweb.com"
MM_URLHTML = GetHTML(MM_URL)
Response.write(GetText(MM_URLHTML,"<Title>","</Title>"))
de forma q te da el titulo de una web.

necesito lo mismo pero con php y me corre prisa, quien me da alguna pista?
  #2 (permalink)  
Antiguo 24/01/2006, 10:27
Avatar de dopon  
Fecha de Ingreso: julio-2005
Ubicación: Cucuta / Colombia
Mensajes: 493
Antigüedad: 18 años, 9 meses
Puntos: 1
hOLAS TRATE DE HACERLO LO MAS SIMILAR EN CUANTO ALOS NOMBRES DE LAS VARIABLES PARA QUE MAS O MENOS TE GUIES

espero derte de ayuda ;)

Código PHP:
function GetHTML($strURL)
{
$ch curl_init();
curl_setopt($chCURLOPT_RETURNTRANSFER,1);
curl_setopt($chCURLOPT_URL,$strURL);
$buffer curl_exec ($ch);
curl_close ($ch);
unset(
$ch);
return 
$buffer;
}


function 
GetTexto($TheStr$sLeft$sRight){
    
$pleft strpos($TheStr$sLeft0);
    if (
$pleft !== false){
        
$pright strpos($TheStr$sRight$pleft strlen($sLeft));
        If (
$pright !== false) {
            return (
substr($TheStr$pleft strlen($sLeft), ($pright - ($pleft strlen($sLeft)))));
        }
    }
    return 
'';

y se puede llamar asi :

Código PHP:

$MM_URL 
"http://www.forosdelweb.com";
$MM_URLHTML GetHTML($MM_URL);
echo 
GetTexto($MM_URLHTML,"<title>","</title>"
  #3 (permalink)  
Antiguo 24/01/2006, 10:34
 
Fecha de Ingreso: enero-2002
Mensajes: 1.438
Antigüedad: 22 años, 3 meses
Puntos: 0
muchas gracias tio,

me tengo q poner con el php, pq me cambiaros de host y ahora no tiene asp,

y es un lio.
  #4 (permalink)  
Antiguo 24/01/2006, 10:39
Avatar de dopon  
Fecha de Ingreso: julio-2005
Ubicación: Cucuta / Colombia
Mensajes: 493
Antigüedad: 18 años, 9 meses
Puntos: 1
Nta dime si te funciona si te sale que la funcion curl_init no esta definida :( es porque no tienes la libreria CURL, y entonces nececitare modificar el script por uno que use funciones de ficheros
  #5 (permalink)  
Antiguo 24/01/2006, 10:53
 
Fecha de Ingreso: enero-2002
Mensajes: 1.438
Antigüedad: 22 años, 3 meses
Puntos: 0
en local w2003 con iis no me funciona,

pero en el host si,

intalare libreria CURL en local (si me aclaro), para poder trabajar, pq lo q te he pasado del titulo es una version simplificada.

de nuevo muchas gracias.
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 19:34.