Skip to content

Instantly share code, notes, and snippets.

@monkeycycle
Forked from kevinohara80/scrape.js
Last active August 29, 2015 14:25
Show Gist options
  • Save monkeycycle/1c57e974c828a47dfd5e to your computer and use it in GitHub Desktop.
Save monkeycycle/1c57e974c828a47dfd5e 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