Skip to content

Instantly share code, notes, and snippets.

@torgeir
Created December 2, 2011 08:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save torgeir/1422295 to your computer and use it in GitHub Desktop.
Save torgeir/1422295 to your computer and use it in GitHub Desktop.
Scraping with jsdom and jquery
/*
$ curl http://www.timeanddate.com/norsk/kalender.html
(...)
<div id=po1 class=po></div>
<h1>Kalender for &#229;r 2011</h1>
<table class="ct" border="0" cellpadding="4" cellspacing="0" align="center">
(...)
$ node scrape.js
This is 2011
*/
var jsdom = require("jsdom");
var url = 'http://www.timeanddate.com/norsk/kalender.html';
jsdom.env(url, [ 'http://code.jquery.com/jquery-1.7.min.js' ], done);
function done (errors, window) {
var year = window.$('h1').text().replace(/[^\d]/g, '');
console.log('This is', year);
window.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment