Skip to content

Instantly share code, notes, and snippets.

@bored-engineer
Created September 8, 2013 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bored-engineer/6487103 to your computer and use it in GitHub Desktop.
Save bored-engineer/6487103 to your computer and use it in GitHub Desktop.
Download the different country codes from the app store.
// Load deps
var request = require("request");
var jsdom = require("jsdom");
// Request the country change page
request({
url: "https://itunes.apple.com/WebObjects/MZStore.woa/wa/countrySelectorPage",
headers: {
"User-Agent": "iTunes/11.0.0 node-appstore"
}
}, function(e, r, body) {
// Load response into jsdom
jsdom.env(body, function (errors, window) {
// Get each script tag
var scripts = (window.document.getElementsByTagName("script"));
// Loop each script
for (var i in scripts) {
// Get the script content
var script = scripts[i].innerHTML;
// If the script actually has content (not src script tag)
if (script) {
// If it's the server data value
if (script.indexOf("its.serverData") !== -1) {
// Get data
var data = (JSON.parse(script.split("its.serverData=")[1]));
console.log(JSON.stringify(data.pageData.pageData.regions));
}
}
}
// Clean up
window.close();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment