这个小脚本应该去网站 http://finra-markets.morningstar.com/BondCenter/Default.jsp
在标签下插入"搜索"在"Symbol/Cusip"
框内输入数字111320AE7
,然后点击"Show Results"
按钮即可获得结果。
Sub SearchSite()
Dim beta
Dim objIE As InternetExplorer
Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate "http://finra-markets.morningstar.com/BondCenter/Default.jsp"
Do While objIE.Busy = True Or objIE.readyState <> 4
DoEvents
Loop
objIE.document.getElementById("firscreener-cusip").Value = "111320AE7"
Set beta = objIE.document.getElementsByClassName("ms-finra-advanced-search-btn")(1)
beta.Click
Do While objIE.Busy = True Or objIE.readyState <> 4
DoEvents
Loop
'objIE.Quit
End Sub
我收到运行时错误91: Object variable or With block variable not set
问题似乎是beta.click
行
我很感激一些帮助。 非常感谢。
答案 0 :(得分:0)
Beta正在引用包含按钮的div。元素数组以0为基数。它们从0开始而不是1。
Sub SearchSite()
Dim beta, buttons, btnReset, btnSubmit
Dim objIE As InternetExplorer
Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate "http://finra-markets.morningstar.com/BondCenter/Default.jsp"
Do While objIE.Busy = True Or objIE.readyState <> 4
Loop
objIE.document.getElementById("firscreener-cusip").Value = "111320AE7"
Set beta = objIE.document.getElementsByClassName("ms-finra-advanced-search-btn")(0)
' <div class="ms-finra-advanced-search-btn">
' <input class="button_blue" value="CLEAR CRITERIA" type="reset">
' <input class="button_blue" value="SHOW RESULTS" type="submit">
' </div>
Set buttons = beta.GetElementsByTagName("input")
WScript.Echo buttons(0).outerHTML
' <input class="button_blue" value="CLEAR CRITERIA" type="reset">
Set btnReset = buttons(0)
' <input class="button_blue" value="SHOW RESULTS" type="submit">
Set btnSubmit = buttons(0)
beta.btnSubmit
Do While objIE.Busy = True Or objIE.readyState <> 4
Loop
objIE.Quit
End Sub