cat dad
cat dad

Reputation: 318

Creating an html document which can be manipulated with the jquery node.js module

I have a string of html from a $.ajax() request (using the jquery node.js package) that I want to scrape data from. From the documentation in the readme it would seem that var $ = require('jquery'); creates a empty html document. Is it possible to replace that DOM with the html string so you can interact with it with jQuery like you would a typical website?

Upvotes: 0

Views: 70

Answers (1)

robertklep
robertklep

Reputation: 203439

Sure:

var $ = require('jquery');

$.get(URL, function(html) {
  var $doc = $(html);
  $doc.find('a').each(function(i, el) {
    console.log('href', $(el).attr('href'));
  });
});

Upvotes: 1

Related Questions