Skip to content

Instantly share code, notes, and snippets.

@notjrbauer
Created December 10, 2013 01:24
Show Gist options
  • Save notjrbauer/7884321 to your computer and use it in GitHub Desktop.
Save notjrbauer/7884321 to your computer and use it in GitHub Desktop.
var request = require('request')
, cheerio = require('cheerio')
, vm = require('vm')
, util = require('util')
, sandbox = {};
request({
uri:'http://account.hirezstudios.com/smitegame/items.aspx',
headers:{
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36'
}
}, function(err, response, body){
if (err) return;
// load html into cheerio
var $ = cheerio.load(body);
// find script that contains your json
// split on semicolons to separate json
var scripts = $('script:contains("jsonItems")').text().split(';');
// run the script in the context of sandbox
vm.runInNewContext(scripts[0], sandbox)
var data = JSON.parse(sandbox.jsonItems);
// mess with data here
console.log(util.inspect(data, false, 2, true));
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment