2017-05-20 2 views
0

Le 16 mai 2017 yahoo.finance changer l'URL pour télécharger le prix EOD. J'essaie d'utiliser la nouvelle URL, mais cela ne fonctionne pas.Erreur de téléchargement de Yahoo Finance

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 

Quelqu'un peut-il m'aider à résoudre mon problème? Avoir quelqu'un le même problème? Merci beaucoup

Andrea

+0

"... mais cela ne fonctionne pas." Qu'est-ce qui ne fonctionne pas? Le site n'est pas accessible, vous obtenez une erreur VBA, les données se chargent mais ce sont des données incorrectes, etc ...? – BruceWayne

+0

Je recommande maintenant d'utiliser l'API de données boursières Alpha Vantage. Cela fonctionne vraiment bien. Je viens d'écrire un article de blog à ce sujet: http://www.the-data-wrangler.com/acquiring-stock-market-data-from-alpha-vantage/ –

Répondre

1

D'abord, le vieux télécharger iChart finance Yahoo est parti pour de bon. Dans l'un des messages du forum, un employé de Yahoo a confirmé que les données EOD gratuites ont été fermées et ne seront pas réintroduites. Consultez ce thread et recherchez la réponse de Nixon. Yahoo est récemment acquis par Verizon, et ce doit être la nouvelle direction. Cependant, si vous consultez la page financière de Yahoo, le lien de téléchargement CSV fonctionne, bien que différemment maintenant. C'est grâce à une nouvelle API qui utilise un jeton d'authentification "crumb" qui est lié à un cookie lorsque vous accédez à la page.

Votre code utilise cette nouvelle API, vous devez donc obtenir les paires de cookies et de miettes correspondantes. J'ai mis en place un peu de code Python3 rapide pour cela (et pour télécharger le même fichier CSV que précédemment) à travers cette nouvelle API. S'il vous plaît vérifier GitHub pour le code source yahoo_quote_download.

+0

Savez-vous un moyen de télécharger des données de vba? ou obtenir la miette pour vba? merci –

+0

Désolé, vous devrez adopter vous-même le code VBA. Je pense que cela devrait fonctionner selon le même principe. – c0redumb

0

J'ai eu le même problème depuis mai. Arrivé avec ce code hier:

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--- 
+1

Il n'est pas clair si ce code est une solution, ou vous parlez, vous avez le même problème avec elle. Dans le premier cas mettre à jour votre réponse, dans la deuxième - poser dans une question distincte. – Qwertiy