使用Node.js和SpookyJS获取亚马逊FBM手续费
请注意
这是我自己用的笔记,没有对代码进行解释。
请将以下内容在汉语中进行同义转述,只需提供一种选项:
代码
'use strict';
const asin = "B012345678";
const price = 2000;
try {
var Spooky = require('spooky');
} catch (e) {
Spooky = require('../lib/spooky');
}
var spooky = new Spooky({
child: { transport: 'http' },
casper: {
logLevel: 'debug',
verbose: true
}
},
function (err) {
if (err) { throw new Error('spooky起動エラー'); }
spooky.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 ');
var FBA_url = "https://sellercentral-japan.amazon.com/fba/profitabilitycalculator/index?lang=ja_JP&asin="
+ asin + "&price=" + price;
spooky.start(FBA_url);
spooky.then(function () {
this.evaluate(function(){
document.getElementById('search-string').value = new String(window.location.href).match(/B0[0-Z]{8}/)[0];
document.getElementsByClassName('a-button-input')[0].click();
});
});
spooky.wait(1000,function(){
this.evaluate(function(){
document.getElementById('afn-pricing').value = new String(window.location.href).match(/price=[0-9]+/)[0].replace(/price=/,'');
document.getElementById('update-fees-link').click();
});
});
spooky.wait(2000,function(){
var result = this.evaluate(function(){
document.getElementById('afn-amazon-fulfillment-fees').click();
return {
asin : new String(window.location.href).match(/B0[0-Z]{8}/)[0],
length : document.getElementById('product-info-length').innerText,
width : document.getElementById('product-info-width').innerText,
height : document.getElementById('product-info-height').innerText,
weight : document.getElementById('product-info-weight').innerText,
categoryCost : document.getElementById('afn-selling-fees').innerText,
packegeCost : document.getElementById('afn-weight-handling-fee').value,
totalCost : new Number(document.getElementById('afn-pricing').value) - new Number(document.getElementById('afn-seller-proceeds').value)
};
});
this.emit('hello',result);
});
spooky.run();
});
spooky.on('error', function (e, stack) {
console.log(e);
});
spooky.on('hello', function (rate) {
//return rate;
console.log(rate);
});
spooky.on('log', function (log) {
if (log.space === 'remote') {
console.log(log.message.replace(/ \- .*/, ''));
}
});