Created
December 10, 2013 01:24
-
-
Save notjrbauer/7884321 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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