返回列表 上一主題 發帖

[發問] 請問如何以VBA擷取網站上的資料?

回復 11# oobird


來問一下 oobird 大大,
oobird大大 問你喔,我用下面這個程式抓出的100筆資料,你知道怎樣讓他抓完整嗎?

原始網站: https://finance.yahoo.com/quote/AAPL/history?period1=1473638400&period2=1505174400&interval=1d&filter=history&frequency=1d

Sub QueryTable()
    Const xlURL As String = "https://finance.yahoo.com/quote/AAPL/history?period1=1473638400&period2=1505174400&interval=1d&filter=history&frequency=1d"
    With ActiveSheet.QueryTables.Add("URL;" & xlURL, Destination:=Range("$A$1"))
        .WebFormatting = xlWebFormattingNone
        .TablesOnlyFromHTML = False
        .RefreshStyle = xlOverwriteCells
        .SaveData = True
        .Refresh 0
    End With
End Sub

TOP

回復 21# ui123

請問這個數值文字如何轉換成日期格式?  謝謝
    period1=1473638400

TOP

回復 22# Scott090

原始網站: https://finance.yahoo.com/quote/AAPL/history?period1=1473638400&period2=1505174400&interval=1d&filter=history&frequency=1d
會自動會轉成,規則不清楚,目前用VBA抓只能抓到100筆

TOP

本帖最後由 Scott090 於 2017-11-11 19:53 編輯

回復 23# ui123


   
原始網站: https://finance.yahoo.com/quote/AAPL/history?period1=1473638400&period2 ...
ui123 發表於 2017-9-14 16:27



period1=1473638400, period2=1505174400 的數字是 日期的秒數數列值
以VBA計算可得
例如 日期是 "2017/1/20",則 period = datevalue("2017/1/20") * 86400 - 2209190400
其中 一日 有86400  秒, 22091904005這個數字是這個網頁對日期演算的一個常數

可以驗算:
a = (1473638400 + 2209190400) / 86400 = 42625.33333
yyyy = year(a) = 2016
mm  = month(a) = 9
dd = day(a) = 12

所以, 1473638400 這個數字 代表 日期 2016/9/12

以上請參考

TOP

回復  Scott090

原始網站: https://finance.yahoo.com/quote/AAPL/history?period1=1473638400&period2 ...
ui123 發表於 2017-9-14 16:27


請參考:
    http://forum.twbts.com/thread-20288-1-1.html

TOP

        靜思自在 : 屋寬不如心寬。
返回列表 上一主題