Googles Importxml Returns "Imported Content Is Empty" Error

I'm trying to get the value of the link of the first youtube video that appears after a youtube search and write it into my google spreadsheet. In order to do this, I am using the in-built IMPORTXML(url, xml_query) function. I have copied the full XPath using google chrome and received the following:

/html/body/ytd-app/div/ytd-page-manager/ytd-search/div[1]/ytd-two-column-search-results-renderer/div/ytd-section-list-renderer/div[2]/ytd-item-section-renderer/div[3]/ytd-video-renderer[1]/div[1]/ytd-thumbnail/a/@href

I have placed the following code in a spreadsheet cell:

=IMPORTXML("", "/html/body/ytd-app/div/ytd-page-manager/ytd-search/div[1]/ytd-two-column-search-results-renderer/div/ytd-section-list-renderer/div[2]/ytd-item-section-renderer/div[3]/ytd-video-renderer[1]/div[1]/ytd-thumbnail/a/@href")

and received the following error:

Imported content is empty.

How can I write the URL of the first youtube video following a youtube search into my spreadsheet cell.

1 Answer

IMPORTXML can't see the DOM shown by Chrome Developer Tools on the Elements tab, it can only see the source code returned by the URL, so instead, you should look at the Sources tab or easier, right click the page and select View page source.

Resources

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest