Skip to content

Instantly share code, notes, and snippets.

@ku
Created February 5, 2012 01:51
Show Gist options
  • Save ku/1741895 to your computer and use it in GitHub Desktop.
Save ku/1741895 to your computer and use it in GitHub Desktop.
#!/usr/bin/env coffee
http = require 'http'
https = require 'https'
zlib = require 'zlib'
cookieStore = {}
uuid = 'x'
appleid = 'ku@gmail.com'
passwd = '*'
# http://blogs.oreilly.com/iphone/2008/08/scraping-appstore-reviews.html
# 143462-1,2 = JP
storeid = '143461'
req = https.request
host: 'p42-buy.itunes.apple.com',
port: 443,
path: "/WebObjects/MZFinance.woa/wa/authenticate?appleId=#{appleid}&rmp=0&password=#{passwd}&attempt=0&accountKind=0&guid=#{uuid}"
headers:
'User-Agent': 'iTunes-iPhone/5.0 (6; 16GB)'
'Accept': '*/*'
'X-Apple-Partner': 'origin.0'
'X-Apple-Connection-Type': 'WiFi'
'X-Apple-Software-Cuid': '4ddd81144e878baa38f15e381c3a572e'
'X-Apple-Client-Versions': 'iBooks/2.0; GameCenter/2.0'
'X-Apple-Client-Application': 'Books'
'X-Apple-Store-Front': '143462-1,2'
'Accept-Encoding': 'gzip, deflate'
, (res) ->
console.log("statusCode: ", res.statusCode)
console.log("headers: ", res.headers)
res.headers['set-cookie'].map (s) ->
s.split(/;/).map (pairs) ->
[k, v] = pairs.split /\=/
if not k.match /^(domain|path|httponly|exipres|version)$/
cookieStore[k] = v
retryWithCookie cookieStore, res.headers.location
res.on 'data', (d) ->
process.stdout.write(d)
req.end()
retryWithCookie = (cookies, location) ->
[x, host, path] = location.match ///https://([-.a-z0-9]+)(/.+)$///
cookieString = Object.keys(cookies).map (k) ->
[k, cookies[k]].join '='
.join '; '
req = https.request
host: host
port: 443,
path: path
headers:
'Cookie': cookieString
'User-Agent': 'iTunes-iPhone/5.0 (6; 16GB)'
'Accept': '*/*'
'X-Apple-Partner': 'origin.0'
'X-Apple-Connection-Type': 'WiFi'
# 'X-Apple-Software-Cuid': '4ddd81144e878baa38f15e381c3a572e'
'X-Apple-Client-Versions': 'iBooks/2.0; GameCenter/2.0'
'X-Apple-Client-Application': 'Books'
# http://www.boingboing.net/2006/01/11/steve-jobs-apple-dis.html
# 'X-Dsid': 0
'X-Apple-Store-Front': storeid
'Accept-Encoding': 'gzip, deflate'
, (res) ->
console.log("statusCode: ", res.statusCode)
console.log("headers: ", res.headers)
res.on 'data', (d) ->
console.log "deflating\n\n"
zlib.gunzip d, (err, d) ->
process.stdout.write(d)
req.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment