Import frem web - show all tables

Simonlandersen

New Member
Joined
Feb 26, 2014
Messages
2
Hi

Im using Excel 2013 without any add-ins. Im currently looking to use excel for basic web scraping. Fx would it be interesting for me to scrape certain youtube videos, so i can easily keep trap of the total views for my videos. But when i try to import from web via excel, it makes almost the entire page into one table. Therefore i cannot get the data that i want, without gettin the rest of the page aswell.

Is there any add-in that can filter the big table on youtube and let me choose only the total views, or is there any way of filtering the data that i extract from the web?

Best regards,
Simon
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi

Welcome to the MrExcel Forum.

Try :-
Code:
Sub YTvideos()
'
' YTvideos Macro
'
'Sheets("YTvideos").Select
On Error GoTo Errortst
Set aBrowser = CreateObject("InternetExplorer.Application")
    With aBrowser
        .Silent = True
        .Visible = False
        .Navigate "http://www.youtube.com/user/- Your account name -/videos"
        While .Busy Or .ReadyState <> 4: DoEvents: Wend
    End With
    
    Set HT = aBrowser.Document
For i = 0 To 14
    Range("A" & i + 1).Value = HT.getElementsByclassName("yt-lockup-title")(i).innertext
'
    Range("B" & i + 1).Value = HT.getElementsByclassName("yt-lockup-meta")(i).innertext
 Next i
Errortst:
 Exit Sub
End Sub

Run on an empty sheet, change the upper limit of the For...Next, outputs to Columns A and B.

hth
 
Upvote 0
Hi

I've found a way to identify how many rows there are with the following code :-
Code:
   x = HT.getElementsByclassName("yt-lockup-title").Length
For i = 0 To x - 1
    Range("A" & i + 1).Resize(, 2) = Array(HT.getElementsByclassName("yt-lockup-title")(i).innertext, HT.getElementsByclassName("yt-lockup-meta")(i).innertext)
Next i

which replaces the existing code from For .... Next to Exit Sub inclusive.

hth
 
Upvote 0

Forum statistics

Threads
1,215,438
Messages
6,124,873
Members
449,192
Latest member
MoonDancer

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