Skip to content

Instantly share code, notes, and snippets.

@Sennahoi
Created August 5, 2014 14:16
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