VBA:从新页面中提取 HTML(相同的 url) [英] VBA: Extract HTML from new page (same url)
问题描述
我需要向此网页提供输入http://kepler.sos.ca.gov/ 然后在我单击提交按钮后收集信息.第一部分(输入+点击提交)运行流畅:
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
然后我需要在新页面的 HTML 脚本中获取元素的内部文本.问题是我无法从新页面的源代码中提取信息.特别是我希望能够得到类似
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
问题是html"仍然指向上一页.我如何引用新的?新页面的url和之前的一样.
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.
推荐答案
您需要在最后一次点击后再次Set html = ie.document
以便您拥有新的文档内容.
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
这篇关于VBA:从新页面中提取 HTML(相同的 url)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!