【发布时间】:2021-07-12 16:53:34
【问题描述】:
我正在尝试对 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
【问题讨论】:
-
文本字段有一个
change event。我很确定您必须触发它才能使您的地址文本适用于该页面。在这里,您可以了解如何获取有关 html 元素的事件的信息以及如何处理它们:stackoverflow.com/questions/63294113/… -
如果您不知道,Zillow 有 API,您应该考虑是否可以满足您的目的 zillow.com/howto/api/faq.htm
-
@zwenn 我试过了,但没有成功。我真的很困惑,我不知道为什么它不起作用。
标签: excel vba internet-explorer web-scraping automation