Yugadi Luitel
New Member
- Joined
- Jul 22, 2016
- Messages
- 12
Hi,
I am trying to import data from this webpage: http://nepalstock.com.np/floorsheet but the problem here is that it displays only 20 rows at a time and has many rows which we have to access by clicking next page at the bottom of page. I therefore need a code that can loop to import entire data by navigating to next page after the first 20 rows are imported and so on until the last page. I got this code below but it keeps on importing same sets of data rather than importing from next page. Any help would be highly appreciated
Sub Extract_data()
Dim url As String, links_count As Integer
Dim i As Integer, j As Integer, row As Integer
Dim XMLHTTP As Object, html As Object
Dim tr_coll As Object, tr As Object
Dim td_coll As Object, td As Object
links_count = 39
For i = 0 To links_count
url = "http://www.admision.unmsm.edu.pe/res20130914/A/011/" & i & ".html"
Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")
XMLHTTP.Open "GET", url, False
XMLHTTP.send
Set html = CreateObject("htmlfile")
html.body.innerHTML = XMLHTTP.ResponseText
Set tbl = html.getelementsbytagname("Table")
Set tr_coll = tbl(0).getelementsbytagname("TR")
For Each tr In tr_coll
j = 1
Set td_col = tr.getelementsbytagname("TD")
For Each td In td_col
Cells(row + 1, j).Value = td.innerText
j = j + 1
Next
row = row + 1
Next
Next
MsgBox "Done"
End Sub
I am trying to import data from this webpage: http://nepalstock.com.np/floorsheet but the problem here is that it displays only 20 rows at a time and has many rows which we have to access by clicking next page at the bottom of page. I therefore need a code that can loop to import entire data by navigating to next page after the first 20 rows are imported and so on until the last page. I got this code below but it keeps on importing same sets of data rather than importing from next page. Any help would be highly appreciated
Sub Extract_data()
Dim url As String, links_count As Integer
Dim i As Integer, j As Integer, row As Integer
Dim XMLHTTP As Object, html As Object
Dim tr_coll As Object, tr As Object
Dim td_coll As Object, td As Object
links_count = 39
For i = 0 To links_count
url = "http://www.admision.unmsm.edu.pe/res20130914/A/011/" & i & ".html"
Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")
XMLHTTP.Open "GET", url, False
XMLHTTP.send
Set html = CreateObject("htmlfile")
html.body.innerHTML = XMLHTTP.ResponseText
Set tbl = html.getelementsbytagname("Table")
Set tr_coll = tbl(0).getelementsbytagname("TR")
For Each tr In tr_coll
j = 1
Set td_col = tr.getelementsbytagname("TD")
For Each td In td_col
Cells(row + 1, j).Value = td.innerText
j = j + 1
Next
row = row + 1
Next
Next
MsgBox "Done"
End Sub