Skip to content

Instantly share code, notes, and snippets.

@Sennahoi
Created August 5, 2014 14:16
Show Gist options
  • Save Sennahoi/e250ad6714bbdd7f2d7f to your computer and use it in GitHub Desktop.
Save Sennahoi/e250ad6714bbdd7f2d7f to your computer and use it in GitHub Desktop.
Extract bookmarks from a netscape bookmark file with node.js
var cheerio = require("cheerio"),
fs = require("fs");
fs.readFile('bookmarks.html', "utf-8", function read(err, data) {
if (err) {
throw err;
}
var $ = cheerio.load(data);
$("a").each(function(index, a) {
var $a = $(a);
var title = $a.text();
var url = $a.attr("href");
var categories = getCategories($a);
console.log(title, url, categories);
});
});
function getCategories($a) {
var $node = $a.closest("DL").prev();
var title = $node.text()
if ($node.length > 0 && title.length > 0) {
return [title].concat(getCategories($node));
} else {
return [];
}
}
@pitambar
Copy link

pitambar commented Nov 1, 2014

thnx buddy this workd for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment