转到网站,填充搜索框,单击搜索按钮

时间:2019-03-27 10:02:47

标签: excel vba

因此,我正尝试访问一个名为realtor.com的网站。 我想根据我的工作表F列中的值列表填写其搜索框,然后单击搜索按钮。 我有一个能够转到该网站的代码,填写了搜索框。但是,一旦单击搜索按钮,就会发生一些奇怪的事情。它根据以前的搜索作为搜索条件进行搜索。 我试图弄清楚会发生什么,我尝试进行手动搜索,然后在将搜索条件放在框上后,以前的搜索就会像下拉菜单一样显示在底部。我认为这与搜索的方式有关,或者在单击搜索按钮时我的代码丢失了。

还有一件事,我的代码还不能基于列表执行搜索,它只能基于特定单元格进行搜索。 谢谢您的帮助。

Sub SearchBot()
'http://automatetheweb.net/
'dimension (declare or set aside memory for) our variables
Dim objIE As InternetExplorer 'special object variable representing the IE browser
Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
Dim y As Integer 'integer variable we'll use as a counter
Dim result As String 'string variable that will hold our result link

'initiating a new instance of Internet Explorer and asigning it to objIE
Set objIE = New InternetExplorer

'make IE browser visible (False would allow IE to run in the background)
objIE.Visible = True

'navigate IE to this web page (a pretty neat search engine really)
objIE.Navigate "https://realtor.com"

'wait here a few seconds while the browser is busy
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

'in the search box put the cell reference
objIE.document.getElementById("rdc-main-search-nav-hero-input").Value = Sheets("Addresses").Range("F2").Value


'click the 'Search' button
objIE.document.getElementsByClassName("rdc-btn_2q8dK rdc-btn-brand_28UWP search-btn")(0).Click


'exit our SearchBot subroutine
End Sub

0 个答案:

没有答案