LoginSignup
0
0

More than 5 years have passed since last update.

MECEなオブジェクトを生成するnode_moduleを作りました

Last updated at Posted at 2016-12-25

The Magus

網羅的にオブジェクトを生成してくれるnode_moduleを作りました。

npm install the-magus

網羅的にスクレイピングしたいときに便利です。

使用例

検索ワードの組み合わせを変えて、検索用のjsonデータを作成します。

実装


// 検索ワードの組み合わせを定義
const word = ['the-fool', 'json スクレイピング'];
const tech = ['node', 'node.js'];
const qiita = ['qiita', ''];

// テンプレートとするデータを定義
const templateData = {
  data: [
    ['goto', 'https://www.google.co.jp'],
    ["type", "form[action='/search']", "$word $tech $qiita"], // $マークの後に変数名
    ["click", "form[action*='/search'] [type=submit]"],
    ["wait", "._NId h3 a"],
    ["snatch", "._NId h3 a", "innerText"]
  ]
};

const magus = new Magus({ word, tech, qiita }, templateData); // { word }はes6のshorhandです
magus.produce((product) => {
  console.info(product);
});

実行結果

/*
{ data:
   [ [ 'goto', 'https://www.google.co.jp' ],
     [ 'type', 'form[action=\'/search\']', 'the-fool node qiita' ],
     [ 'click', 'form[action*=\'/search\'] [type=submit]' ],
     [ 'wait', '._NId h3 a' ],
     [ 'snatch', '._NId h3 a', 'innerText' ] ] }
{ data:
   [ [ 'goto', 'https://www.google.co.jp' ],
     [ 'type', 'form[action=\'/search\']', 'json スクレイピング node.js ' ],
     [ 'click', 'form[action*=\'/search\'] [type=submit]' ],
     [ 'wait', '._NId h3 a' ],
     [ 'snatch', '._NId h3 a', 'innerText' ] ] }
{ data:
   [ [ 'goto', 'https://www.google.co.jp' ],
     [ 'type', 'form[action=\'/search\']', 'the-fool node qiita' ],
     [ 'click', 'form[action*=\'/search\'] [type=submit]' ],
     [ 'wait', '._NId h3 a' ],
     [ 'snatch', '._NId h3 a', 'innerText' ] ] }
{ data:
   [ [ 'goto', 'https://www.google.co.jp' ],
     [ 'type', 'form[action=\'/search\']', 'json スクレイピング node.js ' ],
     [ 'click', 'form[action*=\'/search\'] [type=submit]' ],
     [ 'wait', '._NId h3 a' ],
     [ 'snatch', '._NId h3 a', 'innerText' ] ] }
{ data:
   [ [ 'goto', 'https://www.google.co.jp' ],
     [ 'type', 'form[action=\'/search\']', 'the-fool node qiita' ],
     [ 'click', 'form[action*=\'/search\'] [type=submit]' ],
     [ 'wait', '._NId h3 a' ],
     [ 'snatch', '._NId h3 a', 'innerText' ] ] }
{ data:
   [ [ 'goto', 'https://www.google.co.jp' ],
     [ 'type', 'form[action=\'/search\']', 'json スクレイピング node.js ' ],
     [ 'click', 'form[action*=\'/search\'] [type=submit]' ],
     [ 'wait', '._NId h3 a' ],
     [ 'snatch', '._NId h3 a', 'innerText' ] ] }
{ data:
   [ [ 'goto', 'https://www.google.co.jp' ],
     [ 'type', 'form[action=\'/search\']', 'the-fool node qiita' ],
     [ 'click', 'form[action*=\'/search\'] [type=submit]' ],
     [ 'wait', '._NId h3 a' ],
     [ 'snatch', '._NId h3 a', 'innerText' ] ] }
{ data:
   [ [ 'goto', 'https://www.google.co.jp' ],
     [ 'type', 'form[action=\'/search\']', 'json スクレイピング node.js ' ],
     [ 'click', 'form[action*=\'/search\'] [type=submit]' ],
     [ 'wait', '._NId h3 a' ],
     [ 'snatch', '._NId h3 a', 'innerText' ] ] }
*/

the-foolと併せて使うと凶悪ですね!
http://qiita.com/ito-p/items/29398c1385ad48fc71c3

注意

ご使用は自己責任でお願いします。

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