Created
March 12, 2013 12:04
Revisions
-
yyfrankyy created this gist
Mar 12, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ function findItemIdByTaokeLink(u, cb) { console.log('GET %s', u) request.head({ url: u }, function(err, res) { if (err) return cb(err) console.log('%s %s', res.statusCode, u) var iid = res.headers['at_itemid'] if (iid) return cb(null, iid) var eu = require('querystring').parse(require('url').parse(res.request.href).query).tu console.log('GET', eu) request.head({ url: eu , headers: { Referer: res.request.href } }, function(err, res) { if (err) return cb(err) console.log('%s %s', res.statusCode, u) var iid = res.headers['at_itemid'] if (iid) return cb(null, iid) return cb(new Error('failed to find itemid from this link: ' + u)) }) }) } var u = 'http://s.click.taobao.com/t?e=zGU34CA7K%2BPkqB07S4%2FK0CITy7klxn%2Fr3HZwuuY0VC7BwYOFXUacZzJSTyxeNTKnaTn%2FpS4H9PWTm%2B3LEL1G1C4bUHfRJ8XB%2BLmzokDYziSKBmVXTUBKBhwpTHhaZclHAGqqTrsA5kJ3T2MdT6F1EFOF9TKweNo8oURFVnVPpgXUj7lKMgS0AoM6FYvobEdWoqhbKA%3D%3D&unid=513f11b7328a8&spm=2014.12425299.1.0' findItemIdByTaokeLink(u, function() { console.log(arguments) })