Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleDisplay the text of a Web document without using Internet controls
KeywordsInternet, URL, Web page
CategoriesUtilities
 
Thanks to Trevor Joseph.

Use Internet API functions in wininet.dll. Use InternetOpen to open an Internet session. Use InternetOpenUrl to open a URL. Use InternetReadFile to read the file and use InternetCloseHandle to close the connection.

 
' 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated