VBA: Extract HTML from new page (same url)

496 views Asked by At

I need to feed inputs to this web page http://kepler.sos.ca.gov/ and then collect information once I click the submit button. The first part (inputs+click submit) runs smoothly :

Dim ie As InternetExplorer
'to refer to the HTML document returned
Dim html As HTMLDocument
'open Internet Explorer in memory, and go to website
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "http://kepler.sos.ca.gov/"
'Wait until IE is done loading page
Do While ie.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
Set html = ie.document
html.getElementById("ctl00_content_placeholder_body_BusinessSearch1_RadioButtonList_SearchType_1").Click
html.getElementById("ctl00_content_placeholder_body_BusinessSearch1_TextBox_NameSearch").innerText = "global telematic solutions, LLC"
html.getElementById("ctl00_content_placeholder_body_BusinessSearch1_Button_Search").Click
Do While ie.readyState <> READYSTATE_COMPLETE
DoEvents
Loop

Then I need to get the innertext of an element in the new page's HTML script. The problem is that I can't get to extract info from the source code of the new page. In particular I would like to be able to get something like

Dim SearchCount As String
SearchCount = html.getElementById("ctl00_content_placeholder_body_SearchResults1_TextInfoCorp1_TextInfoSearchResultCounts1_Label_RowCount").innerText

Problem is that "html" still refers to the previous page. How do I refer to the new one? The url of the new page is the same as the previous one.

1

There are 1 answers

0
QHarr On

You need another Set html = ie.document after the last click so you have the new document content.

html.getElementById("ctl00_content_placeholder_body_BusinessSearch1_Button_Search").Click 
While ie.Busy Or ie.READYSTATE < 4: DoEvents: Wend
Set html = ie.document  '<== New HTML document content