Título: Leer pagina web Publicado por: Ner0x en 4 Abril 2006, 02:02 am Hola todos quisiera xfavor q me dieran un ejemplo de como leer una PARTE de una pagina web por ejemplo si vamos a la pagina web del el mercurio (www.elmercurio.cl) arriba hay una parte que sale: "Santiago de Chile, lunes 3 de abril de 2006, actualizado a las 6:39 hrs." que esto oviamente va cambiando... como hago para leer solo esa parte de la pagina, aunque cambie.
Por favor denme un ejemplo. Gracias de antemano Título: Re: Leer pagina web Publicado por: Robokop en 4 Abril 2006, 04:03 am Pues como que para eso necesitarias crear un tipo navegador pero que solamente muestre caracteres y de hay usar la funcion MID para cortar hasta que cantidad de letras quieres leer
Título: Re: Leer pagina web Publicado por: Cicklow en 4 Abril 2006, 17:29 pm Yo entiendo lo que keres hacer, yo realize un crakeador de webs (de files, osea que busca si existe el index.php, index.asp, etc), y para eso lo que ice fue leer el codigo fuente de la web, y verificar si existia la palabra error, 404 etc...
Yo para esto use este programa, que me muestra codigos fuentes de las api de windows: http://www.allapi.net/agnet/appdown.shtml y use este codigo: Código: Const scUserAgent = "API-Guide test program" este te dara un ejemplo de como es leer un file en internet en este caso lee los primeros 1000 bytes de la web, www.microsoft.com/index.htm. ahora para buscar lo que vos keres seria: Reemplasas MsgBox sBuffer Por Código: If Instr(sBuffer,"Santiago de Chile")>0 Then Título: Re: Leer pagina web Publicado por: TrOnNe en 4 Abril 2006, 20:28 pm ciclow, recuerdas q estuvimos hablando sobre los headers en wininet, ok aqui lo publico
Al final un codigo que comprueba una url con apis, no lo hice yo, solo lo adapte para lo que queria. Sirve para saber si una web existe o no sin bajarse ni los 1000kbs de ciclow, esto solo baja los headers si quereis saber el tamaño del fichero, podeis cambiar HTTP_QUERY_STATUS_CODE por HTTP_QUERY_CONTENT_LENGTH etc.. para los que no esten muy puestos, necesita 2 capos de texto y un boton, en el primer campo se pone el servidor ejemplo pepitoperez.soy (sin http) y en el segundo la ruta: usuario/micarpeta/mi.doc Citar Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0 Private Const INTERNET_DEFAULT_HTTP_PORT = 80 Private Const INTERNET_SERVICE_HTTP = 3 Private Const INTERNET_FLAG_RELOAD = &H80000000 Private Const ERROR_INSUFFICIENT_BUFFER = 122 Private Const HTTP_QUERY_CONTENT_TYPE = 1 Private Const HTTP_QUERY_CONTENT_LENGTH = 5 Private Const HTTP_QUERY_EXPIRES = 10 Private Const HTTP_QUERY_LAST_MODIFIED = 11 Private Const HTTP_QUERY_PRAGMA = 17 Private Const HTTP_QUERY_VERSION = 18 Private Const HTTP_QUERY_STATUS_CODE = 19 Private Const HTTP_QUERY_STATUS_TEXT = 20 Private Const HTTP_QUERY_RAW_HEADERS = 21 Private Const HTTP_QUERY_RAW_HEADERS_CRLF = 22 Private Const HTTP_QUERY_FORWARDED = 30 Private Const HTTP_QUERY_SERVER = 37 Private Const HTTP_QUERY_USER_AGENT = 39 Private Const HTTP_QUERY_SET_COOKIE = 43 Private Const HTTP_QUERY_REQUEST_METHOD = 45 Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long Private Declare Function HttpOpenRequest Lib "wininet.dll" Alias "HttpOpenRequestA" (ByVal hHttpSession As Long, ByVal sVerb As String, ByVal sObjectName As String, ByVal sVersion As String, ByVal sReferer As String, ByVal something As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long Private Declare Function HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" (ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, sOptional As Any, ByVal lOptionalLength As Long) As Long Private Declare Function HttpQueryInfo Lib "wininet.dll" Alias "HttpQueryInfoA" (ByVal hHttpRequest As Long, ByVal lInfoLevel As Long, ByRef sBuffer As Any, ByRef lBufferLength As Long, ByRef lIndex As Long) As Long Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer Private Function CheckURL(servidor As String, ruta As String) Dim sBuffer As String * 1024 Dim lBufferLength As Long p_lInternetSession = InternetOpen(App.Title, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0) m_lInternetConnect = InternetConnect(p_lInternetSession, servidor, INTERNET_DEFAULT_HTTP_PORT, vbNullString, vbNullString, INTERNET_SERVICE_HTTP, 0, 0) m_lHttpRequest = HttpOpenRequest(m_lInternetConnect, "HEAD", ruta, "HTTP/1.0", vbNullString, 0, INTERNET_FLAG_RELOAD, 0) If CBool(m_lHttpRequest) Then ' 'prepare string buffer to get server response ' lBufferLength = Len(sBuffer) ' 'send request to remote server. On this state we need Interent connection. 'If system not connected to Internet, dialog with default RAS entry will 'be showed ' iRetVal = HttpSendRequest(m_lHttpRequest, vbNullString, 0, 0, 0) ' 'Use HTTP_QUERY_LAST_MODIFIED flag to try to retrieve value of the LastModified 'header of the server response. If server has returned LastModified header 'value of CheckURL will be True and sBuffer will consist value of the header ' valida = CBool(HttpQueryInfo(m_lHttpRequest, HTTP_QUERY_STATUS_CODE, ByVal sBuffer, lBufferLength, 0)) If sBuffer <> 404 Then CheckURL = True Else CheckURL = False End If End If End Function Private Sub Command1_Click() MsgBox CheckURL(Text1.Text, Text2.Text) End Sub Título: Re: Leer pagina web Publicado por: Cicklow en 4 Abril 2006, 23:32 pm todo muy bien pero el que pregunto no keria eso el keria ver el codigo fuente y solo sakar una parte del texto (osea una parte del codigo fuente), pero lo que haces vos es ver si existe o no la url!!!!!
mi codigo es el que le serivra para el proposito! Título: Re: Leer pagina web Publicado por: TrOnNe en 5 Abril 2006, 13:42 pm jeje sorry, ni lei el post, solo lei el tuyo y pense q era lo otro, pero bueno, si no le vale a el a nosotros si.
un saludo |