Results 1 to 2 of 2
  1. #1
    trb5016 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Location
    Pennsylvania
    Posts
    71

    Get a websites source code with access

    So I've been at this for a while. I've found ways to do it using Visual Studio code. Here's an example of my favorite function:



    Code:
        Public Function DownloadHTMLPage(ByVal _URL As String) As String
            ' <summary>
            'Function to download HTML web page
            ' </summary>
            ' <param name="_URL">URL address to download web page</param>
            ' <returns>HTML contents as a string</returns>
    
            Dim _PageContent As String = Nothing
    
            Try
                ' Open a connection
                Dim _HttpWebRequest As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create(_URL), System.Net.HttpWebRequest)
    
                ' You can also specify additional header values like the user agent or the referer: (Optional)
                _HttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
                _HttpWebRequest.Referer = "http://www.google.com/"
    
                ' set timeout for 10 seconds (Optional)
                _HttpWebRequest.Timeout = 10000
    
                ' Request response:
                Dim _WebResponse As System.Net.WebResponse = _HttpWebRequest.GetResponse()
    
                ' Open data stream:
                Dim _WebStream As System.IO.Stream = _WebResponse.GetResponseStream()
    
                ' Create reader object:
                Dim _StreamReader As New System.IO.StreamReader(_WebStream)
    
                ' Read the entire stream content:
                _PageContent = _StreamReader.ReadToEnd()
    
                ' Cleanup
                _StreamReader.Close()
                _WebStream.Close()
                _WebResponse.Close()
            Catch _Exception As Exception
                ' Error
                Console.WriteLine("Exception caught in process: {0}", _Exception.ToString())
                Return Nothing
            End Try
    
            Return _PageContent
        End Function
    This works great, but I can only use it in a full blown VB Application. What I'd really like to do is get this same functionality in access. All I need is to be able to pull the source code of a given website.

    Access VB doesn't seem to have all that good "System" stuff.

    Is there any way to get that into an access DB so I can use this function?

    Is there a simpler way to get a websites source code that could be used in access?

    Thanks

  2. #2
    c_smithwick is offline Underpaid Programmer
    Windows 7 Access 2003
    Join Date
    Jan 2010
    Location
    Lakeside, CA
    Posts
    49
    Make sure you have a reference to the Microsoft HTML Object Library set and the following function will return the HTML source of the page given a URL

    Public Function getHTMLSource(strURL As String) As String

    Dim objIE As Object

    On Error Resume Next 'Required in case IE is not running, next line will throw an error
    Set objIE = GetObject("InternetExplorer.Application")
    On Error GoTo 0
    If objIE Is Nothing Then
    Set objIE = CreateObject("InternetExplorer.Application")
    End If
    objIE.Visible = True
    objIE.Navigate strURL
    Do While objIE.Busy
    DoEvents
    Loop
    getHTMLSource = objIE.Document.Body.innerHTML
    Set objIE = Nothing
    End Function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM
  2. ComboBox Row Source Value
    By mpbertha in forum Forms
    Replies: 1
    Last Post: 08-21-2009, 06:34 AM
  3. Forms' Record Source
    By Progress2007 in forum Programming
    Replies: 11
    Last Post: 07-27-2009, 11:04 AM
  4. VB code in Access '07 trouble
    By Pauldk in forum Reports
    Replies: 2
    Last Post: 02-18-2009, 03:59 PM
  5. Access 2.0 Viewing Code
    By wollydog in forum Access
    Replies: 0
    Last Post: 12-03-2008, 07:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums