-
Get HTML Code into String from Newly clicked webpage (i.e. URL doesn't change)
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!
-
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.")
-
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_dateInput")
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
-
[VBA]Sub M_snb()
' reference to Microsoft WinHTTP services, version 5.1
With New WinHttpRequest
.Open "get", "http://www.cefconnect.com/Details/Su...spx?ticker=ISL"
.Send
MsgBox .ResponseText
End With
End Sub
[/VBA]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules