prolificinteractive / node-html-to-json

Parses HTML strings into objects using flexible, composable filters.
MIT License
120 stars 13 forks source link

Any way to get everything with request? #2

Closed sumanla13a closed 8 years ago

sumanla13a commented 8 years ago

Is there any way of getting every tags, every attributes from requesting a url?

htmlToJson.request('http://prolificinteractive.com/team', { //some option to get everything }, function (err, result) { console.log(result); });

prolificeric commented 8 years ago

You'd want to write a recursive function that takes an element and returns its tagName and attributes, then maps its children through that same function. For example:

function getTree ($el, $) {
    return {
      tagName: $el[0].tagName,
      attributes: $el[0].getAttributes(), // Not how you do this, just pseudo-code
      children: $el.children().map((child) => getTree($(child)))
   };
}