简体   繁体   中英

How to get “datePublished”: value from website source code into JavaScript code for chrome extension?

I am trying to get the "datePublished": value from a website's source code for my chrome extension. I want to put the value in my JavaScript file so I can use the date the website was published. How exactly would I go about doing that?

The code I want to refer to is the following:

"datePublished":"2017-09-26T20:04:13Z"

How would I get the date into my own code?

Grab the text of the DOM node and use Regex.

var element = document.getElementById("someIDcontainingThatString");
var date = element.innerText.search(/"datePublished":"(.+)"/);

String.prototype.search()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM