雅虎财务错误下载

时间:2017-05-20 09:10:24

标签: vba excel-vba yahoo-finance excel

2017年5月16日yahoo.finance更改网址以下载Eod Price。我尝试使用新的Url,但它不起作用。

With ActiveSheet.QueryTables.Add(Connection:= _
       "TEXT;https://query1.finance.yahoo.com/v7/finance/download/APPL?period1=946854000&period2=1495234800&interval=1d&events=history&crumb=" + mycrumb  _
       , Destination:=Range("Dati!$A$2"))
       .Name = "Data Table"
       .FieldNames = True
       .RowNumbers = False
       .FillAdjacentFormulas = False
       .PreserveFormatting = True
       .RefreshOnFileOpen = False
       .RefreshStyle = xlInsertDeleteCells
       .SavePassword = False
       .SaveData = True
       .AdjustColumnWidth = True
       .RefreshPeriod = 0
       .TextFilePromptOnRefresh = False
       .TextFilePlatform = 850
       .TextFileStartRow = 1
       .TextFileParseType = xlDelimited
       .TextFileTextQualifier = xlTextQualifierDoubleQuote
       .TextFileConsecutiveDelimiter = False
       .TextFileTabDelimiter = True
       .TextFileSemicolonDelimiter = False
       .TextFileCommaDelimiter = True
       .TextFileSpaceDelimiter = False
       .TextFileColumnDataTypes = Array(5, 1, 1, 1, 1, 1, 9)
       .TextFileTrailingMinusNumbers = True
       .Refresh BackgroundQuery:=False
是的,有人可以帮我解决问题吗?有人有同样的问题吗? 非常感谢

Andrea

2 个答案:

答案 0 :(得分:1)

首先,旧的雅虎财经iChart下载已经不复存在了。在其中一篇论坛帖子中,雅虎员工已确认免费的EOD数据已被终止,并且不会重新引入。查看此thread并查找尼克松的回复。雅虎最近被Verizon收购,它必定是新方向。

但是,如果您查看Yahoo财经页面,则CSV下载链接会起作用,但现在不同。它是通过一个新的API,使用在访问页面时链接到cookie的身份验证令牌“crumb”。

您的代码正在使用此新API,因此您必须获得正确匹配的Cookie和crumb对。我已经通过这个新API整理了一些快速的Python3代码(以及像以前一样下载相同的CSV)。请查看GitHub以获取源代码yahoo_quote_download

答案 1 :(得分:0)

自5月以来我一直遇到同样的问题。昨天想出了这个代码:

Sub YahooHistDataHoriztl()
 '---enter in cell A1 for daily:   _https://finance.yahoo.com/quote/AAPL/history?interval=1d
 '---enter in cell A1 for weekly:  _https://finance.yahoo.com/quote/AAPL/history?interval=1wk 
 '---enter in cell A1 for DOW weekly:  _https://finance.yahoo.com/quote/^DJI/history?interval=1wk

 '--- Historical Data will load in columns D through J
 '---This program developed after watching video from 'Automate the Web' 2017-07-03
 '---Use Excel & VBA to automate Internet Explorer -beginner
 '----_https://www.youtube.com/watch?v=GRuzoI_kihI&index=3&list=PL0bsMa4HWk9synJWmuqZmI4Z0a3eurN7V
Dim objIE As InternetExplorer 'special object variable representing the IE browser
Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
Dim y As Integer 'integer variable used as a counter for Rows
Dim z As Integer 'integer variable used as a counter for Columns
Dim result As String 'string variable that will hold our result link
Dim Pather As String
Dim CurrActiveBook As String
Dim CurrActiveSheet As String
Dim drV As String
Dim targetBook As String

 'dimension (declare or set aside memory for) our variables

Application.DisplayAlerts = False

  Pather = ThisWorkbook.Path & "\"   '---holds current path---
  ChDrive Pather                      '---sets excel to the current drive---
  ChDir Pather                       '---sets excel to the current drive---
  drV = Left(Pather, 3)
  CurrActiveBook = ActiveWorkbook.Name
  CurrActiveSheet = ActiveSheet.Name
   targetBook = ActiveWorkbook.Name
   Range("D2:K62").Select
    Selection.ClearContents         '---clears old data

   Set objIE = New InternetExplorer      'initiating a new instance of Internet Explorer and asigning it to objIE
    objIE.Visible = False      'make IE browser visible (False would allow IE to run in the background)
    objIE.navigate Sheets(CurrActiveSheet).Range("A1").Value      'navigate IE to this web page (a pretty neat search engine really)
     Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop     'wait here a few seconds while the browser is busy
      Application.Wait Now + TimeValue("0:00:05")  '---Give an extra 5 seconds to upload

  Range("D1") = "Date"
  Range("E1") = "Open"
  Range("F1") = "High"
  Range("G1") = "Low"
  Range("H1") = "Close"
  Range("I1") = "Adj Close*"
  Range("J1") = "Avg Vol"

  Range("D2").Select
    y = 0   'the first search result will go in row 2
    z = 0
   For Each aEle In objIE.document.getElementsByClassName("Py(10px)")   'for each <a> element in the collection of objects with class of 'result__a'...
      ActiveCell.Offset(y, z).Value = aEle.innerText
        Debug.Print aEle.innerText

 If z > 5 Then   '---Data loads in one column.  This converts to a table.-------
    z = 0
    y = y + 1   'increment our row counter, so the next result goes below
   Application.Wait Now + (TimeValue("0:00:01") / 2) '--giver data an extra 1/2 second to load up---
Else
    If z = 1 Then
     If Right(ActiveCell.Offset(y, z), 5) = "Split" Then   '---Split reset back to date column---
        z = 0
        y = y + 1
         Else
           If Right(ActiveCell.Offset(y, z), 8) = "Dividend" Then   '---Dividend reset back to date column---
            z = 0
            y = y + 1
           Else
         z = z + 1
        End If
      End If
    Else
      z = z + 1
    End If
  End If
   DoEvents
  Next  'repeat times the # of ele's we have in the collection

objIE.Quit      'close the browser
Columns("D:J").Select
 Selection.Columns.AutoFit
  Range("D1").Select

      Application.DisplayAlerts = True
     MsgBox "Done"
   End Sub '---End of program---