Skip to main content

AccessTr.neT


Html'den Excel'e veri çekme

Html'den Excel'e veri çekme

#1
Arkadaşlar internet sayfasından istediğimiz bilgileri Excel sayfasına alabilmek için genel bir program yapmak istiyorum ama burada hangi aynı element başlığına sahip bilgileriden kaçıncı sıradakini alacağımızı nasıl belirtiyoruz mesela aynı bilgi türünden 10 adet var biz üçüncüyü nasıl alacağız

Option Explicit

Const sSiteName = "https://www.encodedna.com/"

Private Sub GetHTMLContents()
    ' Create Internet Explorer object.
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = False          ' Keep this hidden.
   
    IE.Navigate sSiteName
   
    ' Wait till IE is fully loaded.
    While IE.ReadyState <> 4
        DoEvents
    Wend
   
    Dim oHDoc As HTMLDocument    ' Create document object.
    Set oHDoc = IE.Document
   
    Dim oHEle As HTMLUListElement    ' Create Html element (<ul>) object.
    Set oHEle = oHDoc.getElementById("ulPost")  ' Get the element reference using its ID.
   
    Dim iCnt As Integer
   
    ' Loop through elements inside the <ul> element and find <h2>, which has the texts we want.
    With oHEle
        For iCnt = 0 To .getElementsByTagName("h2").Length - 1
            Debug.Print .getElementsByTagName("h2").Item(iCnt).getElementsByTagName("a").Item(0).innerHTML
        Next iCnt
    End With
   
    ' Clean up.
    IE.Quit
    Set IE = Nothing
    Set oHEle = Nothing
    Set oHDoc = Nothing
End Sub
@benbendedeilem
Son Düzenleme: 11/01/2020, 11:14, Düzenleyen: accessman.
Cevapla
#2
Add Microsoft Html Object Library Reference
To make the macro work with an external source such as a webpage, we’ll need Microsoft’s Internet Explore (to open the page and will remain hidden). In-addition, to read and extract contents of Html elements, we’ll have to create few objects using a library.
Therefore, first add the Microsoft Html Object Library reference to the application. From the top menu of your Vba editor, click Tools -> References…. In the References window, find and select Microsoft Html Object Library and click OK.
@benbendedeilem
Son Düzenleme: 11/01/2020, 11:15, Düzenleyen: accessman.
Cevapla

Bir hesap oluşturun veya yorum yapmak için giriş yapın

Yorum yapmak için üye olmanız gerekiyor

ya da