Reputation: 318
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
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