我正在尝试从网站收集数据,一旦源是字符串形式,这应该是可管理的。环顾四周,我已经收集了一些可能的解决方案但是遇到了所有问题:
以下是我遇到的问题:
代码1:
Sub getData() Dim url As String,即As Object,状态为Integer Dim text As Variant,startS As Integer,endS As Integer
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = 0
url = "http://www.eoddata.com/stockquote/NASDAQ/AAPL.htm"
ie.Navigate url
state = 0
Do Until state = 4
DoEvents
state = ie.readyState
Loop
text = ie.Document.Body.innerHTML
startS = InStr(ie.Document.Body.innerHTML, "7/26/2012")
endS = InStr(ie.Document.Body.innerHTML, "7/25/2012")
text = Mid(ie.Document.Body.innerHTML, startS, endS - startS)
MsgBox text
答案 0 :(得分:1)
如果我试图从该页面的08/10/12开始关闭开盘价,这与我假设您正在做的类似,我会做这样的事情:
Set ie = New InternetExplorer
With ie
.navigate "http://eoddata.com/stockquote/NASDAQ/AAPL.htm"
.Visible = False
While .Busy Or .readyState <> READYSTATE_COMPLETE
DoEvents
Wend
Set objHTML = .document
DoEvents
End With
Set elementONE = objHTML.getElementsByTagName("TD")
For i = 1 To elementONE.Length
elementTWO = elementONE.Item(i).innerText
If elementTWO = "08/10/12" Then
MsgBox (elementONE.Item(i + 1).innerText)
Exit For
End If
Next i
DoEvents
ie.Quit
DoEvents
Set ie = Nothing
您可以修改此项以运行HTML并提取您想要的任何数据。迭代+2会返回高价等等。
由于该页面上有很多日期,您可能还需要检查它是否在最近结束日价格与公司资料之间。