htm-to-json
v0.1.4
Published
to convert html string to json file , and also get data through tag name ,tag id and attribute value.
Downloads
650
Maintainers
Readme
html-to-json
A small library providing utility methods for html string.
Installation
npm install htm-to-json --save
Usage
var hObj = require('html-to-json');
var str = "<!DOCTYPE html><html lang='en'><head><title>html-to-json</title><meta charset='UTF-8'><div id='username'>praveen</div>";
hObj.convert_html_to_json(str,function(err,data){
if(err) throw err;
console.log(data);
});
output:-
{ html: [ { lang: 'en' } ],
head: [],
title: [ { innerHTML: 'html-to-json' } ],
meta:
[ { charset: 'UTF-8' },
div: [ { id: 'username', innerHTML: 'praveen' } ] }
Functions
- convert_html_to_json
- get_data_by_id
- get_data_by_tag
- get_data_by_attr_val
hObj.convert_html_to_json(str,function(err,jdata){
if(err) throw err;
console.log(jdata);
//get data by tag Id
hObj.get_data_by_id(jdata,'username',function(err,data){
console.log(data);
});
//get data by tag name eg:div
hObj.get_data_by_tag(jdata,'div',function(err,data){
console.log(data);
});
//get data by tag attribute value eg: first_name
hObj.get_data_by_attr_val(jdata,'username',function(err,data){
console.log(data);
});
});
Tests
npm test.js
Release History
- 0.1.1 Initial release