Excel VBA无法获取网站元素和输入数据 [英] Excel VBA cannot get element and input data a website
问题描述
我正在尝试编写一个 VBA 脚本来将关键字(例如:Amuse)输入到以下网站的文本框地图定位"中,然后单击开始"以自动搜索该地点.CentaMap
I am trying to write a VBA script to input keywords (For expamle: Amuse) into the following website's textbox "Map Positioning" and click "go" to search the place automatically. CentaMap
这是我为文本框找到的 html 脚本
Here is the html script I found for the textbox
<INPUT onkeyup=searchBoxTextChanged(this.value); id=qbyid style="FONT-SIZE: 10pt" maxLength=60 name=q autocomplete="off">
知道正常的做法是使用get element by id然后在里面输入这样的数据.但是我被卡住了,因为我无法使用以下代码获取文本框元素:
Knowing that the normal way to do is to use get element by id then input such data in it. However I am being stuck as I cannot get the textbox element with the following codes:
Sub SubCentalineAutomation()
Dim myIE As InternetExplorer
Const url As String = "http://hk.centamap.com/gc/home.aspx?lg=en"
Set myIE = New InternetExplorer
myIE.navigate (url)
Do While myIE.readyState <> 4
DoEvents
Loop
myIE.Visible = True
myIE.document.getElementsByName("q")(0).Value = "Amuse"
End Sub
我尝试使用 getElementsById("qbyid") 替换代码,但是 VBA 也找不到该元素.有人可以帮忙吗?
I tried to replace the codes by using getElementsById("qbyid") instead however VBA cannot find the element too. Can anybody help on this?
推荐答案
需要参考
- 微软互联网控制
- 微软 HTML 对象库
Sub SubCentalineAutomation()
Dim myIE As InternetExplorer
Dim frame As MSHTML.HTMLFrameElement
Dim inp As MSHTML.HTMLInputElement
Const url As String = "http://hk.centamap.com/gc/home.aspx?lg=en"
Set myIE = New InternetExplorer
myIE.navigate (url)
Do While myIE.readyState <> 4
DoEvents
Loop
myIE.Visible = True
Set frame = myIE.document.getElementsByName("search")(0)
Set inp = frame.contentDocument.getElementsByName("q")(0)
inp.Value = "Amaze"
End Sub
这篇关于Excel VBA无法获取网站元素和输入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!