Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/07/2008, 06:36
Ganchito
 
Fecha de Ingreso: diciembre-2006
Mensajes: 11
Antigüedad: 17 años, 4 meses
Puntos: 0
De acuerdo Como puedo leer datos Web?

Buenas.

Hasta ahoa estaba haciendo servir un comando llamado GetUrlSource, el código es el siguiente:

Cita:
Public 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
Public Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal sURL As String, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Public Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

Public Const IF_FROM_CACHE = &H1000000
Public Const IF_MAKE_PERSISTENT = &H2000000
Public Const IF_NO_CACHE_WRITE = &H4000000

Private Const BUFFER_LEN = 256


Public Function GetUrlSource(sURL As String) As String

Dim sBuffer As String * BUFFER_LEN, iResult As Integer, sData As String
Dim hInternet As Long, hSession As Long, lReturn As Long

'get the handle of the current internet connection
hSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)
'get the handle of the url
If hSession Then hInternet = InternetOpenUrl(hSession, sURL, vbNullString, 0, IF_NO_CACHE_WRITE, 0)
'if we have the handle, then start reading the web page
If hInternet Then
'get the first chunk & buffer it.
iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
sData = sBuffer
'if there's more data then keep reading it into the buffer
Do While lReturn <> 0
iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
sData = sData + Mid(sBuffer, 1, lReturn)
Loop
End If

'close the URL
iResult = InternetCloseHandle(hInternet)

GetUrlSource = sData

End Function
Lo que hace es leer los datos de una Web y te los devuelve con lo que quieras, por ejemplo, yo lo uso así:

Cita:
GS = GetSource("http://miweb.es/index.html")

First = Split(GS, "#")(1)
First = Split(First, "//")(0)
Lo que hago es leer el código que hay en miweb.es, y con un Split hago que coja e texto que hay entre el "#" y el "//"

Hasta aquí todo bien, me lo lee y tal, de hecho ya me va bien, pero supongamos que he de leer 40 hojas web diferentes, claro, irá muuuuuuuuy lento.. como puedo hacer para que vaya rádido? O un código que haga lo mismo y sea muchísimo mas rápido?

Muchas gracias!