Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 138
  • Last Modified:

Download the contents of a web page

I am interested in downloading the contents of a web page and then parsing the file out for what i need.

Not even sure how to begin.
0
tpiazza
Asked:
tpiazza
1 Solution
 
robertleesCommented:
You should start by reading about the Inet control (standard VB control shown as Microsoft Internet Transfer Control in the Project/Components list).

0
 
GivenRandyCommented:
For the most basic browser, do the following.  Select the WebBrowser control(Project -> Components -> Microsoft Internet Controls) and add one to the form. In the form code, do something like:

WebBrowser1.Navigate "http://www.experts-exchange.com"

That's all it takes!  If you want the browser to display in the whole form, add this:

---
Private Sub Form_Resize()
    WebBrowser1.Top = Form1.Top
    WebBrowser1.Left = Form1.Left
    WebBrowser1.Height = Form1.Height
    WebBrowser1.Width = Form1.Width
End Sub
---

If you want a more capable browser, use the VB Application Wizard:

Start VB
Select "File" then "New Project"
Select "VB Application Wizard"
Select "Next" 5 times
Select "Yes" (for Internet access)
Select "Next" 3 times
Select "Finish"

When you run your new application, select "View" then "Web Browser"
0
 
emadatCommented:
Copy this in a module and use it.
Usage:
sString = GetHTML("http:\\www.domain_name.com")

'====================================================
Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Const INTERNET_DEFAULT_HTTP_PORT = 80
Public Const INTERNET_SERVICE_HTTP = 3
Public Const INTERNET_FLAG_RELOAD = &H80000000
Public Const HTTP_QUERY_STATUS_CODE = 19
Public Const HTTP_ADDREQ_FLAG_ADD = &H20000000

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 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
Public 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
'Public 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
Public Declare Function HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" (ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal sOptional As String, ByVal lOptionalLength As Long) As Long
Public 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
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Public Declare Function HttpAddRequestHeaders Lib "wininet.dll" Alias "HttpAddRequestHeadersA" (ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lModifiers As Long) As Integer
Public Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumberOfBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Public Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternet&, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength&, ByVal dwFlags&, ByVal dwContext&) As Long


Public Function GetHTML(strURL As String) As String
Const BufferSize = 16384
Dim hSession&, hURL&
Dim Buffer As String * BufferSize
Dim BufferLen&
Dim sAppName$, sResult$
    sAppName = "MyApplicationName"
    hSession = InternetOpen(sAppName, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    hURL = InternetOpenUrl(hSession, strURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    sResult = ""
    Do
        InternetReadFile hURL, Buffer, Len(Buffer), BufferLen
        If BufferLen > 0 Then sResult = sResult & Left(Buffer, BufferLen)
    Loop Until BufferLen = 0
    GetHTML = sResult
    InternetCloseHandle hURL
    InternetCloseHandle hSession
End Function
'====================================================
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now