Hello,
I am kind of new in programming and VBA. I hope that some smart guys/girls can help me out here.
I would like to extract data from webpage, but so far I got little success.
The problem is, that I don't know how to refer to speciefic field in webpage (and to get data from there). For example I want to get telefon (phone nr).
in HTML it is something like this: <th class="d-border" data-field_id="s_phone" data-group_id="5"><div class="t-wrap">Phone</div></th>
link where I want to get data: h**ps://www.e-krediidiinfo.ee/10832919-TEREBINT%20O%C3%9C
I have tried with getElementsByTagName , getElementById, getElementsByClassName but no success 
Below you can find partly working code:
Option Explicit
Sub TableExample()
Dim IE As Object
Dim doc As Object
Dim strURL As String
strURL = "https://www.e-krediidiinfo.ee/10832919-TEREBINT%20O%C3%9C" ' replace with URL of your choice
Set IE = CreateObject("InternetExplorer.Application")
With IE
'.Visible = True
.navigate strURL
Do Until .ReadyState = 4: DoEvents: Loop
Do While .Busy: DoEvents: Loop
Set doc = IE.Document
GetAllTables doc
.Quit
End With
End Sub
Sub GetAllTables(doc As Object)
' get all the tables from a webpage document, doc, and put them in a new worksheet
Dim ws As Worksheet
Dim rng As Range
Dim tbl As Object
Dim rw As Object
Dim cl As Object
Dim tabno As Long
Dim nextrow As Long
Dim I As Long
Set ws = Worksheets.Add
For Each tbl In doc.getElementsByTagName("TABLE")
tabno = tabno + 1
nextrow = nextrow + 1
Set rng = ws.Range("B" & nextrow)
rng.Offset(, -1) = "Table " & tabno
For Each rw In tbl.Rows
For Each cl In rw.Cells
rng.Value = cl.outerText
Set rng = rng.Offset(, 1)
I = I + 1
Next cl
nextrow = nextrow + 1
Set rng = rng.Offset(1, -I)
I = 0
Next rw
Next tbl
ws.Cells.ClearFormats
End Sub
Bookmarks