VBA Web Scrapping - XML Method

SharmaAntriksh

New Member
Joined
Nov 8, 2017
Messages
31
I am trying to scrap video names and hyperlinks from one of the channels i have subscribed, the goal is to get all videos names on that page and create a hyperlink, below is the code that i have created and works so far, the problem i am facing is that it only fetches the data that is displayed once we load youtube channel, and as more videos appear after scrolling down it can't get them.

Is there a way to resolve this?

Code:
'first create reference to Microsoft XML V6.0  and Microsoft HTML Object library
Sub BrowseToAWebsiteXML()


    Dim XMLPage As MSXML2.XMLHTTP60
    Dim HTMLDoc As MSHTML.HTMLDocument
    
    Dim Vid As MSHTML.IHTMLElement, VidColl As MSHTML.IHTMLElementCollection
    
    Set XMLPage = New MSXML2.XMLHTTP60
    Set HTMLDoc = New MSHTML.HTMLDocument
    
    XMLPage.Open "GET", "https://www.youtube.com/channel/UCXhiOv9VT_0XSnVXyEh4pWw/videos"
    XMLPage.send
    
    HTMLDoc.body.innerHTML = XMLPage.responseText
    
    Set VidColl = HTMLDoc.getElementsByTagName("a")
    
    For Each Vid In VidColl
        If Vid.className = "yt-uix-sessionlink yt-uix-tile-link  spf-link  yt-ui-ellipsis yt-ui-ellipsis-2" Then
            Debug.Print Vid.getAttribute("title")
        End If
    Next Vid
    
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,435
Members
448,898
Latest member
dukenia71

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