Skip to content

Instantly share code, notes, and snippets.

@kevinohara80
Created October 26, 2012 20:52
Show Gist options
  • Save kevinohara80/3961421 to your computer and use it in GitHub Desktop.
Save kevinohara80/3961421 to your computer and use it in GitHub Desktop.
Simple node.js WSJ Prime Rate scraper web service
var express = require('express');
var http = require('http');
var path = require('path');
var request = require('request');
var $ = require('cheerio');
var WSJ_PRIME_URL = 'http://www.bankrate.com/rates/interest-rates/wall-street-prime-rate.aspx';
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.methodOverride());
app.use(app.router);
});
// curl http://localhost:3000/rates/wsjprime
app.get('/rates/wsjprime', function(req, res) {
request(WSJ_PRIME_URL, function(err, resp, html) {
if(err) return res.send('ERROR');
var h = $.load(html);
return res.send(h('td.tabledataoddnew:nth-child(2)').text());
});
});
http.createServer(app).listen(app.get('port'), function(){
console.log('Rate scraper running on port ' + app.get('port'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment