Skip to content

Instantly share code, notes, and snippets.

@lifeparticle
Last active February 1, 2021 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lifeparticle/5905aef5719e7d935d4fb7f172a29188 to your computer and use it in GitHub Desktop.
Save lifeparticle/5905aef5719e7d935d4fb7f172a29188 to your computer and use it in GitHub Desktop.
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