PDA

View Full Version : Get HTML Code into String from Newly clicked webpage (i.e. URL doesn't change)



bcbc123
03-06-2013, 06:01 PM
Hi guys,

So I'm trying to get the HTML source code from a website, except the website URL never changes. This is what I have so far/what I need help with:

Sub MyVBA()

Dim ie, objDoc, htmlInput As Object
Dim strURI, htmlDOC As String

struURI = "....somewebsite.com"

Set ie = CreateObject("internetexplorer.application")
ie.Navigate strURI

Do
If ie.ReadyState = 4 Then
ie.Visible = True
Exit Do

Else
DoEvents
End If
Loop

Set objDoc = ie.document

Set htmlInput = objDoc.getElementById("insertIDhere")
htmlInput.Click

htmlDOC = objDOC.body.innerHTML
msgBox(htmlDOC)

End Sub

So VBA clicks on the button that I want, and InternetExplorer goes to the new webpage (this part of my code works correctly). The URL, however, never changes. So when I try to get the HTML source code of the new webpage through VBA, VBA gets the HTML source from the original webpage, not the new webpage that I want.

Is there a way to get the source code from the new webpage, not the original webpage?

Thanks!

Doug Robbins
03-07-2013, 12:33 AM
Where are you providing a new value for struURI?

You could use an InputBox for the purpose

stuURI = InputBox("Enter the address of the website.")

bcbc123
03-07-2013, 11:45 AM
I don't think that's the problem because the URL never changes. I'll be more specific and put exactly what I'm trying to do:

Sub MyVBA()

Dim ie, objDoc, htmlInput As Object
Dim strURI, htmlDOC As String

strURI = "www[dot]cefconnect[DOT]com/Details/Summary[DOT]aspx?ticker=ISL"

Set ie = CreateObject("internetexplorer.application")
ie.Navigate strURI

Do
If ie.ReadyState = 4 Then
ie.Visible = True
Exit Do

Else
DoEvents
End If
Loop

Set objDoc = ie.document

'click on the pricing history tab
Set htmlInput = objDoc.getElementById("__tab_ctl00_contents_SummaryContainer_PricingTab")
htmlInput.Click

'Change the date to 1/25/13
Set htmlInput = objDoc.getElementById("ctl00_contents_SummaryContainer_PricingTab_ucPricing_PriceDatePicker_dateIn put")
htmlInput.Value = "2013-01-25-00-00-00"

'Click GO
Set htmlInput = objDoc.getElementById("ctl00_contents_SummaryContainer_PricingTab_ucPricing_PriceHistoryGo")
htmlInput.Click

'get the new source code (notice the URL never changes, but the source code does change)
htmlDOC = objDOC.body.innerHTML
msgBox(htmlDOC)

End Sub

snb
03-07-2013, 02:28 PM
Sub M_snb()
' reference to Microsoft WinHTTP services, version 5.1

With New WinHttpRequest
.Open "get", "http://www.cefconnect.com/Details/Summary.aspx?ticker=ISL"
.Send
MsgBox .ResponseText
End With
End Sub