Code:
var DomExtractor = require('./index.js');
var html = '<h3 data-universe="marvel">List of Superheros:</h3><ul class="heros"><li data-id="1"><span>Spiderman<span></li><li data-id="2"><span>Captain America<span></li><ul>';
var query = {
universe: 'h3[data-universe]',
heros: {
_: 'ul.heros li',
name: 'span',
id: '@[data-id]'
}
};
var results = (new DomExtractor(html)).extract(query);
console.log(results);
Output:
{ universe: 'marvel',
heros:
[ { name: 'Spiderman', id: '1' },
{ name: 'Captain America', id: '2' } ] }