0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NodejsでspookyJSを使ってFBA手数料を取得する

0
Last updated at Posted at 2018-07-03

注意

自分用メモです。コードの解説はしていません。

コード

spooky_sample.js
'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(/ \- .*/, ''));
    }
});
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?