LoginSignup
10
11

More than 5 years have passed since last update.

Node.jsでスクレイピングからファイル保存[メモ]

Last updated at Posted at 2013-07-22
var scraper = require('scraper');
scraper('http://hoge.com/hoge', function(err, $) {
    // データを取得
    if (err) {throw err;}
    var ans = /<div>([0-9]*)<\/div>/ig.exec($('html').html());
    if (ans === null || !ans[1]) { throw 'No match'; }

    // 書き込みデータ作成
    var dt = new Date();
    var dtString = ("0" + dt.getHours()).slice(-2) + ':' + ("0" + dt.getMinutes()).slice(-2);

    // ファイルへ保存
    var fs = require('fs');
    fs.appendFileSync("/temp/data.txt", dtString + "\t" + ans[1] + "\n");
});
10
11
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
10
11