YouTube Scraping, XPath, and Google Sheets
APIs can give you much more power but they are often overkill for what people are trying to around here- lightweight social media
Here’s a lightweight example of how you can use Google Sheets and the IMPORTXML function to grab quite a bit of data from various video pages with no API or technical skills.
Straight off, we’re going to want the URL of the video. We’ll put that in column A and we’ll use it as a variable in all our other formulas.
Getting the Paths to the Data
So how’d that come to be? A2 is just asking what URL we want to go to. The XPATH stuff gets a little more interesting. It’s going to look for any class that is named watch-title. I found out the title was in that div by right clicking on the title and choosing inspect in Chrome. The appended  will only give us the first item that meets those qualifications. Otherwise the title shows up twice.
The rest of the formulas are pretty much variations on that theme.
- =IMPORTXML(A2,”//*[contains(@class, ‘watch-view-count’)]”) – View count
- =IMPORTXML(A2,”(//*[contains(@class, ‘like-button-renderer-like-button’)])”) – Likes count
- =IMPORTXML(A2,”(//*[contains(@class, ‘like-button-renderer-dislike-button’)])”) – Dislikes count
- =IMPORTXML(A2,”(//*[contains(@class, ‘yt-user-info’)])”) – User name