Last active
February 1, 2021 05:56
-
-
Save lifeparticle/5905aef5719e7d935d4fb7f172a29188 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
posts = [] | |
Array.prototype.forEach.call(document.getElementsByClassName("nd rk rd x"), function(post) { | |
postObj = {}; | |
postObj.title = post.getElementsByTagName("a")[0].innerText; | |
postObj.link = post.getElementsByTagName("a")[0].href; | |
postObj.pubDate = post.getElementsByClassName("dv")[1].innerText; | |
posts.unshift(postObj); | |
}); | |
cleanPosts = []; | |
Array.prototype.forEach.call(posts, function(post) { | |
post.link = post.link.replace("?source=your_stories_page-------------------------------------", ""); | |
post.pubDate = post.pubDate.replace("on", ""); | |
post.pubDate = post.pubDate.includes(",") ? new Date(post.pubDate) : new Date(post.pubDate+" "+new Date().getFullYear()); | |
post.pubDate = post.pubDate.toISOString().replace('T', ' ').substr(0, 19) | |
cleanPosts.push(post); | |
}); | |
var jsonData = JSON.stringify(cleanPosts, null, "\t"); | |
console.log(jsonData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment