返回列表 上一主題 發帖

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

回復 5# GBKEE

大大請問一下,我用下面這個程式抓出的資料跟原始網站的資料比較下,下面有一段沒有抓不到,是不是有參數沒設好? 要wait嗎?因為下面有顯示Loading more data...但是我不知道怎樣讓他跑完

原始網站: 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

回復 5# GBKEE

GBKEE大大,我原本想用這幾天問你的,抓Crumb位置來下載csv檔案,但沒有成功,所以想換下面那個網址試試,但抓出的資料不完整,如果可以抓取完整就太好了
https://finance.yahoo.com/quote/AAPL/history?period1=1473638400&period2=1505174400&interval=1d&filter=history&frequency=1d
紅框下面是要抓的資料:

javascript:;

Data 1.PNG (52.44 KB)

Data 1.PNG

TOP

回復 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

回復 22# Scott090

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

TOP

        靜思自在 : 成功是優點的發揮,失敗是缺點的累積。
返回列表 上一主題