Created
March 12, 2013 12:04
-
-
Save yyfrankyy/5142379 to your computer and use it in GitHub Desktop.
读取淘客链接对应的商品ID
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 characters
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) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment