A HTML to JSON library.
hQuery.toJson(url [, mapping], callback)
hQuery is designed to convert html to json object, JQuery like.
var mapping = {
title:"head title",
};
hQuery.toJson("http://www.baidu.com", mapping, function(err, json){
console.log(json);
});
title:"head title"
get title element text by default. use title:{selector:"head title", attr:"href"}
to get attributes.
use foreach like this. Point .
mean current element.
var options = {
p: {
selector: "p#nv a",
foreach: {
name: ".",
url: {
selector: ".",
attr: "href"
}
}
};
hQuery.toJson("http://www.baidu.com", mapping, function(err, json){
console.log(json);
});
var mapping = {
title: function(elem){
return elem.text();
}
};
hQuery.toJson("http://www.baidu.com", mapping, function(err, json){
console.log(json);
});