Scrap data from website multiple pages

mji007

New Member
Joined
Jan 21, 2023
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
  2. Web
Hi,

I intend to get data from following website multiple pages with dates but unable to understand how do via VBA i am using Excel 2019

Also I tried excel query but following msg appeared
Details: "The remote server return an HTTP status code '500' when trying to access 'Karachi Stocks | MFS Open Position'."

Any helpful solution please
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I tried but only getting 1st row of the required table instead of all with from to date including multiple pages.

VBA Code:
Sub test() 
    Dim xml    As Object
    Dim html   As Object
    Dim elemcollection As Object
    Dim result As String
    Dim t As Long, r As Long, c As Long, ActRw As Long
    Set xml = CreateObject("MSXML2.XMLHTTP.6.0")
    With xml
        .Open "GET", "https://khistocks.com/market-data/mfs-rates.html", False
        .send
    End With
    result = xml.responseText
    Set html = CreateObject("htmlfile")
    html.body.innerHTML = result
    Set elemcollection = html.getElementsByTagName("table")
    For t = 0 To elemcollection.Length - 1
        If t = 0 Then
            For r = 0 To elemcollection(t).Rows.Length - 1
                For c = 0 To elemcollection(t).Rows(r).Cells.Length - 1
                    ThisWorkbook.Sheets("Sheet17").Cells(ActRw + r + 1, c + 1) = elemcollection(t).Rows(r).Cells(c).innerText
                Next c
            Next r
            ActRw = ActRw + elemcollection(t).Rows.Length + 1
        End If
    Next t
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top