Extracting YouTube views online using getElementsByClassName in VBA

zcahlmc

New Member
Joined
Aug 5, 2019
Messages
5
Hi there. My code is running and generating the necessary timestamps to viewership data from a YouTube link, however I can't seem to get the viewership to copy and print. Any help to extract this information from the YouTube code would be much appreciated.

Thanks

Here is a link as an example:
https://www.youtube.com/watch?v=xXh1QLK6f5s

<tbody>
</tbody>

Code:
Sub Collectest()

Application.Wait (Sheet1.Range("f2").Value)


Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = False
.navigate Range("b4").Value




Do
DoEvents
Loop Until ie.readystate = READYSTATE_COMPLETE
Dim Doc As HTMLDocument
Set Doc = ie.Document
While ie.readystate <> 4


Wend


On Error Resume Next


Application.Wait (Now + TimeValue("00:00:05"))


Dim s As Integer
Dim i As Integer
s = Sheet1.Range("i3").Value
For i = 0 To s

Range("b7").Offset(i, (i2 * 2)).Value = Doc.getElementsByClassName("view-count style-scope yt-view-count-renderer")

Range("b7").Offset(i, (i2 * 2) - 1).Value = Now()


Range("b7").Offset(i, (i2 * 2) - 1).Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    ActiveSheet.Paste
    Application.CutCopyMode = False


Application.Wait (Now + TimeValue("00:00:01"))


Next i


Application.EnableEvents = True


End With
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,

this runs fairly smooth:

Code:
$url = "https://www.youtube.com/watch?v=xXh1QLK6f5s"
$ret = iwr $url
$pos = $ret.Content.IndexOf('view-count')
$ret.Content.Substring($pos, 50)


# 880.627 @ Sep 26
 
Upvote 0

Forum statistics

Threads
1,214,851
Messages
6,121,931
Members
449,056
Latest member
denissimo

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