' Return the source of a web page
Private Function GetWebData(strUrl As String) As String
Dim hInternet, hSession, lngDataReturned As Long
Dim intReadFileResult As Integer
Dim strBuffer As String * 128
Dim strTotalData As String
'retrieve a handle to the current internet session
hSession = InternetOpen("vb wininet", 1, vbNullString, _
vbNullString, 0)
If hSession Then
'retrieve a handle to the strUrl
hInternet = InternetOpenUrl(hSession, strUrl, _
vbNullString, 0, INTERNET_FLAG_NO_CACHE_WRITE, _
0)
End If
If hInternet Then
'start reading the web page into a buffer, 128
' bytes at a time
intReadFileResult = InternetReadFile(hInternet, _
strBuffer, STRING_SIZE, lngDataReturned)
'copy the contents of the buffer to strTotalData
strTotalData = strBuffer
'While there is still data left,
Do While lngDataReturned <> 0
'keep reading the web page into the buffer,
intReadFileResult = InternetReadFile(hInternet, _
strBuffer, STRING_SIZE, lngDataReturned)
'and keep appending the contents of strTotalData
strTotalData = strTotalData + Mid(strBuffer, 1, _
lngDataReturned)
Loop
End If
'return our internet handle
intReadFileResult = InternetCloseHandle(hInternet)
GetWebData = strTotalData
'manually clear the string, just in case
strTotalData = ""
End Function
|