home github twitter linkedin

Quickly extract all links with timestamp from a HackerNews page

Here's a quick script I wrote to get all links along with the associated link title and timestamp from a HackerNews page and print out a CSV. I use it within the browser developer tools Javascript console.

var size =  document.getElementsByClassName("athing").length;
var line = "";
for (i = 0; i < size; i++) {
    var title = document.getElementsByClassName("athing")[i].getElementsByClassName("titleline")[0].getElementsByTagName("a")[0].innerText;
    var url = document.getElementsByClassName("athing")[i].getElementsByClassName("titleline")[0].getElementsByTagName("a")[0].href;
    var date = document.getElementsByClassName("athing")[0].nextSibling.getElementsByClassName("age")[0].title;

    line = line.concat("\"", date, "\"").concat(",\"", url, "\"").concat(",\"", title, "\"").concat("\n");