How to Extract the Publishing Date From a YouTube Video Page?

I wanted to get the publishing date using this this piece of code:

document.querySelector("#tooltip").innerText;

in a run Javascript action but failed.

I don't know why it's failed and is there a way to get the publishing date from a YouTube page?

Please post a specific YouTube page, so we can test the same data...

Okay...

It looks like you can pull the published date out of the page meta data:

document.querySelector("meta[itemprop~=uploadDate]").outerHTML

I've only tested this on a couple of pages, so don't hold me to it.

I thought any YouTube page is ok. :smile:
Such as this one :point_right: How To Guard Anyone (Lockdown Defensive Tips)

Experience has taught me to never assume such a thing.

It's all to easy to work at cross purposes when you're not on the same page...

Data on websites can be very different in different sections.

My code above seems to work on your page though.

It's all to easy to work at cross purposes when you're not on the same page...

You're right. Thank you for reminding me.

Your code works well. I can use your code in this way to get the publishing date! :point_right:

Really happy to sort this out and thank you for your help! :smiley:

1 Like

This is probably WAY more than you want, and way more complicated, but Google has an API for all sorts of things YouTube-related. API Reference  |  YouTube Data API  |  Google Developers.

I use it to pull up comments I haven't answered on my YT channel. But I'll admit that the code is extremely complicated.

1 Like

Yes and no... :sunglasses:

Can you post a very simple working example or two, so we have a starting point?

TIA.

No. The entire JavaScript part of my Custom HTML Prompt is over 1600 lines, with 1400 of them dedicated to accessing the API. For doing simple tasks, this is WAAAY overkill. I just needed this much code because of how I handle searching for comments I haven't replied to, which is much harder than just asking for recent comments.

With that said, using the API is simple in principle. You just make HTTP requests constructed a particular way, and process the results, which come back as JSON.

The Google API docs are actually quite good, and they show you simple examples that you can use right from the API pages, and show you the code behind them which is minimal.

But to use the API for any real work, you need to set up credentials and get an API key. There is a publicly available general-purpose key (if memory serves) that the docs use, but to do anything worthwhile, you have to set up your own Credentials and get an API key of your own, which is free but has a quota limit per day.

IIRC, you get your API key at https://console.cloud.google.com/apis/dashboard, but that might only be for when you actually have credentials, I don't remember.

Last note. I use a Custom HTML Prompt window now (actually, 2 prompts) so I can make use of KM to do some things I can't do in a normal web page. But originally, the code was just an HTML file I opened in a browser. So you don't really need KM for using the API at all.

1 Like