Skip to content

Instantly share code, notes, and snippets.

@dviramontes
Created April 1, 2013 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dviramontes/5285887 to your computer and use it in GitHub Desktop.
Save dviramontes/5285887 to your computer and use it in GitHub Desktop.
Screen Scraping with jsdom and node.js technique: http://blog.nodejitsu.com/jsdom-jquery-in-5-lines-on-nodejs
// The code creates a new jsdom window
// and adds jQuery to the document via a script element.
// Although it is just an illustrative
// example it is easy to modify it to work with
// real pages retrieved from the Internet.
var jsdom = require('jsdom');
jsdom.env({
html: "<html><body></body></html>",
scripts: [
'http://code.jquery.com/jquery-1.5.min.js'
]
}, function (err, window) {
var $ = window.jQuery;
$('body').append("<div class='testing'>Hello World</div>");
console.log($(".testing").text()); // outputs Hello World
});
// more examples: https://gist.github.com/indexzero/1009644
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment