xpath extract YouTube video name?

Viewed 2023

How to extract data from the following h1 tag using Google Sheets =IMPORTXML() Function?

HTML tag:

<h1 class="title style-scope ytd-video-primary-info-renderer"><yt-formatted-string force-default-style="" class="style-scope ytd-video-primary-info-renderer">XPath query, IMPORTXML &amp; Google Sheets - Advanced Tutorial</yt-formatted-string></h1>

Result:

XPath query, IMPORTXML & Google Sheets - Advanced Tutorial
2 Answers

The syntax is straightforward, first the url of your xml, then your xpath. Be careful with single and double quotes.

=IMPORTXML("link to your xml file or webpage";"//h1")

or to be more specific :

=IMPORTXML("link to your xml file or webpage";"//h1[@class='title style-scope ytd-video-primary-info-renderer']")

EDIT : And to get what you need :

=IMPORTXML("https://www.youtube.com/watch?v=pwZ44kAeiOo";"//span[@class='watch-title']")

YT Title

Related