Created
April 1, 2013 16:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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