【问题标题】:VBA: Extract HTML from new page (same url)VBA:从新页面中提取 HTML(相同的 url)
【发布时间】:2018-06-30 05:20:17
【问题描述】:

我需要向此网页http://kepler.sos.ca.gov/ 提供输入,然后在单击提交按钮后收集信息。第一部分(输入+点击提交)运行顺利:

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 脚本中获取元素的内部文本。问题是我无法从新页面的源代码中提取信息。特别是我希望能够得到类似的东西

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

问题是“html”仍然指的是前一页。我如何引用新的?新页面的url和上一个一样。

【问题讨论】:

    标签: html vba web-scraping


    【解决方案1】:

    在最后一次单击后,您需要另一个 Set html = ie.document,以便获得新的文档内容。

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-30
      • 1970-01-01
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多