Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

uoiszero/hQuery

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hQuery -- Convert Html to Json

NPM

A HTML to JSON library.

Simple to use

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);
});

Attribute

title:"head title" get title element text by default. use title:{selector:"head title", attr:"href"} to get attributes.

Foreach

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);
});

Function

var mapping = {
    title: function(elem){
        return elem.text();
    }
};

hQuery.toJson("http://www.baidu.com", mapping, function(err, json){
    console.log(json);
});

About

A HTML to JSON library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.