Sub web_automation()
Dim Iobj As InternetExplorer
Dim Htmlele As IHTMLElement
Dim i As Integer
i = 1
Set Iobj = New InternetExplorer
Iobj.Visible = True
Iobj.navigate "https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations)"
Application.Wait Now + TimeValue("00:00:05")
For Each Htmlele In Iobj.document.getElementsByClassName("wikitable")(0).getElementsByTagName("tr")
With ActiveSheet
.Range("A" & i).Value = Htmlele.Children(0).textContent
.Range("B" & i).Value = Htmlele.Children(1).textContent
.Range("C" & i).Value = Htmlele.Children(2).textContent
.Range("D" & i).Value = Htmlele.Children(3).textContent
.Range("E" & i).Value = Htmlele.Children(4).textContent
End With
i = i + 1
Next Htmlele
End Sub
Dim Iobj As InternetExplorer
Dim Htmlele As IHTMLElement
Dim i As Integer
i = 1
Set Iobj = New InternetExplorer
Iobj.Visible = True
Iobj.navigate "https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations)"
Application.Wait Now + TimeValue("00:00:05")
For Each Htmlele In Iobj.document.getElementsByClassName("wikitable")(0).getElementsByTagName("tr")
With ActiveSheet
.Range("A" & i).Value = Htmlele.Children(0).textContent
.Range("B" & i).Value = Htmlele.Children(1).textContent
.Range("C" & i).Value = Htmlele.Children(2).textContent
.Range("D" & i).Value = Htmlele.Children(3).textContent
.Range("E" & i).Value = Htmlele.Children(4).textContent
End With
i = i + 1
Next Htmlele
End Sub
Comments
Post a Comment