Created
September 8, 2013 18:13
-
-
Save bored-engineer/6487103 to your computer and use it in GitHub Desktop.
Download the different country codes from the app store.
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
// 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