VBA单击并在XMLHTTP上键入

时间:2018-12-28 04:58:57

标签: vba excel-vba

我想知道是否可以使用XMLHTTP键入并单击网页。例如,我想去Yahoo Finance并在搜索栏中输入内容,然后点击Submit。

我不想使用Internet Explorer,而是想使用XMLHTTP。而且我不希望仅连接URL。这是我所拥有的:

Dim XHTTP As New MSXML2.XMLHTTP60
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim HTTPCol, HTTPCol2 As MSHTML.IHTMLElementCollection
Dim HTTPEl As MSHTML.IHTMLElement

XHTTP.Open "GET", "https://finance.yahoo.com/", False
XHTTP.send

If XHTTP.Status <> 200 Then
 MsgBox "Problem"
 Exit Sub
 End If

HTMLDoc.body.innerHTML = XHTTP.responseText

Set HTTPCol = HTMLDoc.getElementsByName("yfin-usr-qry")

For Each  HTTPEl In HTTPCol 
IDTarget.Value = "AAPL"
Next

Set HTTPCol2  = HTMLDoc.getElementsByName("search-button")

Set HTTPCol2(0).Click

'But then the "click" does submit to go to the next page where I can grab data from this page. I would like to, for example, get the stock price of apple on this new page. 

0 个答案:

没有答案