0

次のリンクから取得した情報で Excel ファイルを常に更新する必要があります (警告、ウクライナ語): ウクライナ財務省の Web サイトへのリンク

有用なデータは HTML タグでラップされています<tbody></tbody>

テーブルから情報を取得する同様のコードが必要です

Set htm = CreateObject("htmlFile")' #it doesn't work on mac os machine, but perfectly performs on windows
    With CreateObject("msxml2.xmlhttp")
        .Open "GET", <site_url_goes_here>, False
        .send
        htm.body.innerhtml = .responsetext
    End With

    With htm.getelementbyid("item")' <<<<<---what should I write here in order to parse data from the web-site table?
        Sheet2.Cells(Row, 4).Value = p
        For x = 1 To .Rows.Length - 1
            For y = 0 To .Rows(x).Cells.Length - 1
                Sheet2.Cells(Row, y + 1).Value = .Rows(x).Cells(y).innertext
            Next y
            Row = Row + 1
        Next x
    End With`
4

1 に答える 1

0

以下のコードは、60 秒ごとにhttp://www.minfin.gov.uaから更新されたデータを取得します。

Sub getData()

    Application.OnTime Now + TimeSerial(0, 0, 60), "finance_data"

End Sub

Private Sub finance_data()
    Dim url As String, lastRow As Long
    Dim XMLHTTP As Object, html As Object
    Dim tbl As Object, obj_tbl As Object
    Dim TR As Object, TD As Object
    Dim row As Long, col As Long

    lastRow = Range("A" & Rows.Count).End(xlUp).row

    url = "http://www.minfin.gov.ua/control/uk/publish/article?art_id=384069&cat_id=234036" & "&r=" & WorksheetFunction.RandBetween(1, 10000)

    Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")
    XMLHTTP.Open "GET", url, False
    XMLHTTP.setRequestHeader "Content-Type", "text/xml"
    XMLHTTP.send

    Set html = CreateObject("htmlfile")
    html.body.innerHTML = XMLHTTP.ResponseText
    Set obj_tbl = html.getelementsbytagname("table")

    row = 1
    col = 1

    For Each tbl In obj_tbl
        If tbl.classname = "MsoNormalTable" Then
            Set TR = tbl.getelementsbytagname("TR")

            For Each obj_row In TR
                For Each TD In obj_row.getelementsbytagname("TD")
                    Cells(row, col) = TD.innerText
                    col = col + 1
                Next
                col = 1    ' reseting the value
                row = row + 1
            Next
        End If
    Next

    getData
End Sub
于 2013-11-15T03:01:21.520 に答える