Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.
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");
});
sngmr
やぁやぁ。sngmrだよ! コネクションワークスの森 真吾だよ! Blogは近況報告なんかに特化させて、技術的なことはこっちに書いていこうと思うよ。 モトクロスとプログラムと粉砕骨折と: http://d.hatena.ne.jp/sngmr コネクションワークス: http://connectionworks.jp
http://sngmr.jp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away