Scrape Tables from Multiple URLs in single sheet

Jasvindra

New Member
Joined
Jul 31, 2018
Messages
35
How can i use the below code to scrap tables from multiple URLs and paste them one below other on single sheet

Sub GetCourseList()


Dim URL As String
Dim qt As QueryTable
Dim ws As Worksheet

Set ws = Worksheets.Add

URL = "https://www.wiseowl.co.uk/courses/"

Set qt = ws.QueryTables.Add( _
Connection:="URL;" & URL, _
Destination:=Range("A1"))

With qt
.RefreshOnFileOpen = True
.Name = "CoursesFromWiseOwl"
.FieldNames = True
.WebSelectionType = xlAllTables
.Refresh BackgroundQuery:=False
End With

End Sub
 

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows
Re: Scrap Tables from Multiple URLs in single sheet

Create a sheet with the name of "Urls", in column A from row 2 put each of the urls.

Sheet: Urls

A
1Courses
2https://www.wiseowl.co.uk/courses/
3https://www.wiseowl.co.uk/courses/

<colgroup><col style="width: 30px; font-weight: bold;"><col style="width: 253px;"></colgroup><tbody>
</tbody>


Create another sheet and name it "Destination" to put the list of courses

Try with this macro:

Code:
Sub GetCourseList()


    Dim wUrl As Range, URL As String
    Dim qt As QueryTable
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim u As Long
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    Set ws1 = Sheets("Urls")
    Set ws2 = Sheets("Destination")
    
    ws2.Cells.Clear
    
    For Each wUrl In ws1.Range("A2", ws1.Range("A" & Rows.Count).End(xlUp))
        URL = wUrl.Value '"https://www.wiseowl.co.uk/courses/"
        u = ws2.Range("A" & Rows.Count).End(xlUp).Row + 2
        
        Set qt = ws2.QueryTables.Add( _
            Connection:="URL;" & URL, _
            Destination:=ws2.Range("A" & u))
        
        On Error Resume Next
        With qt
            .RefreshOnFileOpen = True
            .Name = "CoursesFromWiseOwl"
            .FieldNames = True
            .WebSelectionType = xlAllTables
            .Refresh BackgroundQuery:=False
        End With
        On Error GoTo 0
    Next
    
    MsgBox "End"
    
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,123,140
Messages
5,599,964
Members
414,352
Latest member
macquarie_jchan58

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
Top