Search code examples
google-sheetsxpathxml-parsinggoogle-sheets-formula

How can you use IMPORTXML to get a YouTube Thumbnail from the XML feed?


I'm trying to populate a Google Sheet with a table that contains the 10 most recent YouTube videos from a channel along with the video title, video URL, date, description, and thumbnail image.

When I try to use IMPORTXML on the Google Sheet, I get an error that "Imported content is empty":

screenshot of Google Sheets error

Here's the formula in the field:

=IMPORTXML("https://www.youtube.com/feeds/videos.xml?channel_id=UCmGSJVG3mCRXVOP4yZrU1Dw","/feed/entry[1]/media:group/media:thumbnail/@url")

I've tried testing the xpath on a few online testers, and they seem to return the URL, but it doesn't work in Google Sheets.


Solution

  • Well that is a problem with namespaces. See i.e. this good answer

    In your case the XPath could be:

    /*[local-name()='feed']/*[local-name()='entry'][1]/*[local-name()='group']/*[local-name()='thumbnail']/@url