Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fetch data from webpage using MSXML2.xmlHttp

Status
Not open for further replies.

patriciaxxx

Programmer
Jan 30, 2012
277
GB
I need help with the following two problems.

I have the Access module below which goes to the webpage to check if the holders number has won anything and the results are displayed in the webpage. (Please note the holders number is an example).

My first problem is how can I retrieve those results and debug.Print them? I have tried to identify them in the html but can’t find them?

Code:
[COLOR=#204A87]Public Sub HaveIWon()
Dim objIE As Object

Set objIE = CreateObject("InternetExplorer.Application")

With objIE
    .Visible = True
    .Navigate "[URL unfurl="true"]http://www.nsandi.com/savings-premium-bonds-have-i-won"[/URL]
    Do While .readyState <> 4: DoEvents: Loop
    With .Document.Forms(1)
        .all("pbhn").Value = "123AB123456" 'Example holders number
        .all("chkdrw").selectedIndex = 0
    End With
    .Document.Forms(1).submit
    Debug.Print .Document.body.outerText
End With

Set objIE = Nothing

End Sub
[/color]

My second problem is how can I use MSXML2.xmlHttp to do the same job i.e. go to the page enter the form details and retrieve the same data.

Code:
[COLOR=#204A87]With CreateObject("MSXML2.xmlHttp")
    .Open "GET", "[URL unfurl="true"]http://www.nsandi.com/savings-premium-bonds-have-i-won",[/URL] False
    .send
    Do Until .readyState = 4: DoEvents: Loop
    If .Status = 200 Then
        Set oHtml = New HTMLDocument
        oHtml.body.innerHTML = .responseText
    End If
End With
[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top