vendredi 1 juillet 2016

VBA: handling data in Document Object Model


I am currently trying to scrap data from a website using VBA. I am following this tutorial and hence my code is the following one:

Sub Foo()

    Dim appIE As Object
    Set appIE = CreateObject("internetexplorer.application")

    With appIE
        .Navigate "https://www.ishares.com/it/investitore-privato/it/prodotti/251843/ishares-euro-high-yield-corporate-bond-ucits-etf"
        .Visible = True
    End With

    Do While appIE.Busy
        DoEvents
    Loop

    Set allRowOfData = appIE.document.getElementsByClassName("visible-data totalNetAssets")
    Dim myValue As String
    myValue = allRowOfData.Cells(1).innerHTML
    MsgBox myValue

End Sub

Unfortunately there are some differences between data I want to scrap and those ones used in the example: this line

myValue = allRowOfData.Cells(1).innerHTML

is wrong according to VBA debug.

Anyone could provide me with some explanations about why that doesn't work and how am I supposed to pick the right method to scrap HTML pages?


Aucun commentaire:

Enregistrer un commentaire