我正在用vb.net编写程序。我的程序将生成每只股票的收盘价回报图。现在,我必须访问雅虎财经并选择日期并下载。然后我在 Excel 中打开该文件并复制收盘价列。然后我将这些值粘贴到记事本中。最后,我的程序读取记事本文件并生成图表。
那么,我是否可以只在 vb.net 中输入符号,然后获得所需的所有值,而无需执行所有这些步骤?
盗自 http://www.vb-helper.com/howto_net_graph_stock_history.html
下面的代码将为您提供从雅虎检索股票报价所需的信息。您只需将股票代码传递给 GetStockPrices 即可。我相信,默认情况下,它会从谷歌财经下载一年的历史数据。
实际上,您所需要做的就是谷歌:“vb.net 下载股票报价历史记录” - 您会发现大量的东西。
' Get the prices for this symbol.
Private Function GetStockPrices(ByVal symbol As String) As _
List(Of Single)
' Compose the URL.
Dim url As String = _
"http://www.google.com/finance/historical?output=csv&q=" _
& symbol
' Get the result.
' Get the web response.
Dim result As String = GetWebResponse(url)
' Get the historical prices.
Dim lines() As String = result.Split( _
New String() {vbCr, vbLf}, _
StringSplitOptions.RemoveEmptyEntries)
Dim prices As New List(Of Single)()
' Process the lines, skipping the header.
For i As Integer = 1 To lines.Length - 1
Dim line As String = lines(i)
prices.Add(Single.Parse(line.Split(","c)(4)))
Next i
Return prices
End Function
我已尝试上面的代码,但在 GetWebResponse 中出现错误 使用此功能之前需要导入任何库吗? 谢谢