excel vba 中的 Zillow 网络抓取(大问题帮助)
Zillow web scraping in excel vba (Big issue help)
我正在尝试网络抓取 Zillow。我目前正在使用网络自动化,但是我无法搜索我想要的位置。该值出现在搜索栏上,但当它提交时它不会更改并返回到同一页面。这就像即使我改变它,预先建立的价值仍然存在。请帮助我,我已经尝试了很多天,但我无法得到答案。
Zillow 的代码。---------------------------------------- --------------------------------------
<input class="react-autosuggest__input" role="combobox" aria-expanded="false" aria-controls="react-autowhatever-1" aria-owns="react-autowhatever-1" aria-autocomplete="list" aria-label="Search: Suggestions appear below" type="text" placeholder="Address, neighborhood, or ZIP" value="new jersey" autoComplete="off">
Sub zillow()
Dim ie As New SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument
Dim zillowinput As MSHTML.IHTMLElementCollection
Dim zillowinput2 As MSHTML.IHTMLElementCollection
Dim direc As String
Dim iny As MSHTML.IHTMLElementCollection
Dim inys As MSHTML.IHTMLElement
ie.Visible = True
ie.navigate "https://www.zillow.com/homes/new-jersey_rb/"
Do While ie.readyState <> READYSTATE_COMPLETE Or ie.Busy
Loop`enter code here`
Set doc = ie.document
direc = Range("D5").Value
Application.Wait Now() + #12:00:02 AM#
Set inys = doc.getElementById("srp-search-box")
Set inys = doc.getElementsByTagName("input")(0)
inys.Focus
inys.Value = "35 Krakow St, Garfield, NJ 07026"
inys.Blur
**strong text**
doc.forms(0).submit
可以使用 SendKeys 触发搜索框中的更改事件。您可以使用 SendKeys
模拟用户输入来设置搜索框的值,然后按 Enter 键进行搜索。
您可以参考下面的工作代码:
Sub zillow()
Dim ie As New SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument
Dim inys As MSHTML.IHTMLElement
ie.Visible = True
ie.navigate "https://www.zillow.com/homes/new-jersey_rb/"
Do While ie.readyState <> READYSTATE_COMPLETE Or ie.Busy
Loop
Set doc = ie.document
Application.Wait Now() + #12:00:02 AM#
Set inys = doc.getElementsByTagName("input")(0)
inys.Focus
SendKeys ("35 Krakow St, Garfield, NJ 07026")
Application.Wait (Now + TimeValue("00:00:02"))
SendKeys ("{ENTER}")
End Sub
IE 中的结果:
我正在尝试网络抓取 Zillow。我目前正在使用网络自动化,但是我无法搜索我想要的位置。该值出现在搜索栏上,但当它提交时它不会更改并返回到同一页面。这就像即使我改变它,预先建立的价值仍然存在。请帮助我,我已经尝试了很多天,但我无法得到答案。
Zillow 的代码。---------------------------------------- --------------------------------------
<input class="react-autosuggest__input" role="combobox" aria-expanded="false" aria-controls="react-autowhatever-1" aria-owns="react-autowhatever-1" aria-autocomplete="list" aria-label="Search: Suggestions appear below" type="text" placeholder="Address, neighborhood, or ZIP" value="new jersey" autoComplete="off">
Sub zillow()
Dim ie As New SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument
Dim zillowinput As MSHTML.IHTMLElementCollection
Dim zillowinput2 As MSHTML.IHTMLElementCollection
Dim direc As String
Dim iny As MSHTML.IHTMLElementCollection
Dim inys As MSHTML.IHTMLElement
ie.Visible = True
ie.navigate "https://www.zillow.com/homes/new-jersey_rb/"
Do While ie.readyState <> READYSTATE_COMPLETE Or ie.Busy
Loop`enter code here`
Set doc = ie.document
direc = Range("D5").Value
Application.Wait Now() + #12:00:02 AM#
Set inys = doc.getElementById("srp-search-box")
Set inys = doc.getElementsByTagName("input")(0)
inys.Focus
inys.Value = "35 Krakow St, Garfield, NJ 07026"
inys.Blur
**strong text**
doc.forms(0).submit
可以使用 SendKeys 触发搜索框中的更改事件。您可以使用 SendKeys
模拟用户输入来设置搜索框的值,然后按 Enter 键进行搜索。
您可以参考下面的工作代码:
Sub zillow()
Dim ie As New SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument
Dim inys As MSHTML.IHTMLElement
ie.Visible = True
ie.navigate "https://www.zillow.com/homes/new-jersey_rb/"
Do While ie.readyState <> READYSTATE_COMPLETE Or ie.Busy
Loop
Set doc = ie.document
Application.Wait Now() + #12:00:02 AM#
Set inys = doc.getElementsByTagName("input")(0)
inys.Focus
SendKeys ("35 Krakow St, Garfield, NJ 07026")
Application.Wait (Now + TimeValue("00:00:02"))
SendKeys ("{ENTER}")
End Sub
IE 中的结果: