Skip to content

Instantly share code, notes, and snippets.

@mortenjust
Forked from torgeir/scrape.js
Created March 17, 2012 23:57
Show Gist options
  • Save mortenjust/2066779 to your computer and use it in GitHub Desktop.
Save mortenjust/2066779 to your computer and use it in GitHub Desktop.
Scraping with jsdom and jquery
/*
https://github.com/tmpvar/jsdom/tree/master/lib
$ 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