我有一个VBA代码,可以在Zillow上成功搜索房屋,但是我试图提取网站上显示状态的部分(class =“ status”),并在excel电子表格上显示结果。
Sub getHTMLdocument()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLButtons As MSHTML.IHTMLElementCollection
Dim HTMLButton As MSHTML.IHTMLElement
Dim stat As MSHTML.IHTMLElement
IE.Visible = True
IE.navigate "zillow.com/homes"
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = IE.Document
Set HTMLInput = HTMLDoc.getElementById("citystatezip")
HTMLInput.Value = "21371 Estepa Circle Huntington Beach"
Set HTMLButtons = HTMLDoc.getElementsByTagName("button")
HTMLButtons(0).Click
Set stat = HTMLDoc.getElementById("yui_3_18_1_1_1548832597156_4287")
Debug.Print stat.getAttribute("href")
End Sub
最终,我还希望VBA从电子表格中提取数据并通过按一下按钮自动加载每个数据。
例如:
111 Main st [为Zillow加载111的按钮]
211 Main st [为211加载Zillow的按钮]
311 Main st [为311加载Zillow的按钮] ...
但是,如果至少能在excel上显示class =“ status”部分,我将不胜感激