Scrape Tables from Multiple URLs in single sheet

Jasvindra

New Member
Joined
Jul 31, 2018
Messages
38
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
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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
https://www.wiseowl.co.uk/courses/
https://www.wiseowl.co.uk/courses/

<colgroup><col style="width: 30px; font-weight: bold;"><col style="width: 253px;"></colgroup><tbody>
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CACACA]#CACACA[/URL] , align: center"]1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=92D050]#92D050[/URL] , align: center"]Courses[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CACACA]#CACACA[/URL] , align: center"]2[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CACACA]#CACACA[/URL] , align: center"]3[/TD]

</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
 
Upvote 0

Forum statistics

Threads
1,223,713
Messages
6,174,036
Members
452,542
Latest member
Bricklin

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