?
Solved

Download the contents of a web page

Posted on 2003-03-24
3
Medium Priority
?
137 Views
Last Modified: 2012-05-04
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
Comment
Question by:tpiazza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Expert Comment

by:robertlees
ID: 8198315
You should start by reading about the Inet control (standard VB control shown as Microsoft Internet Transfer Control in the Project/Components list).

0
 
LVL 9

Accepted Solution

by:
GivenRandy earned 500 total points
ID: 8198356
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
 
LVL 3

Expert Comment

by:emadat
ID: 8198393
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question