VBA: Extract HTML from new page (same url)

蓝咒 提交于 2021-01-28 17:43:36

问题


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:


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


来源:https://stackoverflow.com/questions/30733392/vba-extract-html-from-new-page-same-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!