{"id":19,"date":"2011-04-19T23:51:00","date_gmt":"2011-04-19T14:51:00","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=19"},"modified":"2017-02-03T01:20:36","modified_gmt":"2017-02-02T16:20:36","slug":"post-19","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/node-js\/19","title":{"rendered":"node.io\u3067\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0"},"content":{"rendered":"<p>\u53c2\u8003<br \/>\n<a href=\"https:\/\/gunmagisgeek.com\/blog\/?p=1948\">node.js\u3067\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\uff08cheerio\u7248\uff09<\/a><br \/>\n\u2191\u3053\u3061\u3089\u306e\u65b9\u304c\u7c21\u5358\u304b\u3082<\/p>\n<hr>\n<p>Scraping the web with Node.io<br \/>\n<a href=\"http:\/\/www.coderholic.com\/scraping-the-web-with-node-io\/\">http:\/\/www.coderholic.com\/scraping-the-web-with-node-io\/<\/a><\/p>\n<p>\u4e0a\u8a18\u3001\u30d6\u30ed\u30b0\u8a18\u4e8b\u3092\u8aad\u3093\u3067\u8208\u5473\u6df1\u304b\u3063\u305f\u306e\u3067node.io\u3092\u3061\u3087\u3063\u3068\u4f7f\u3063\u3066\u307f\u307e\u3057\u305f\u3002\u516c\u5f0f\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306f\u4ee5\u4e0b\u3002<\/p>\n<p>node.io<br \/>\n<a href=\"https:\/\/github.com\/chriso\/node.io\/wiki\">https:\/\/github.com\/chriso\/node.io\/wiki<\/a><\/p>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306fnpm\u3067\u3002<\/p>\n<pre class=\"lang:sh decode:true \" >$ npm install node.io<\/pre>\n<p>\u3068\u308a\u3042\u3048\u305a\u3001\u8a66\u3057\u306b&#8221;\u306f\u3066\u30d6&#8221;\u304b\u3089\u300c\u3044\u307e\u8a71\u984c\u300d\u30ad\u30fc\u30ef\u30fc\u30c9\u30ea\u30f3\u30af\u3092\u53d6\u5f97\u3057\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"lang:js decode:true \" title=\"hatena.js\">    var nodeio = require('node.io');\r\n    exports.job = new nodeio.Job({\r\n        input:false,\r\n        run:function(){\r\n            var self = this, url = &quot;http:\/\/b.hatena.ne.jp\/hotentry&quot;;\r\n            this.getHtml(url, function(err, $){\r\n                if(err){\r\n                    self.exit(err);\r\n                }else{\r\n                    $('.top_keyword a').each(function(a){\r\n                        self.emit(a.text);\r\n                    });               \r\n                }\r\n            })\r\n        }\r\n    })<\/pre>\n<p>\u4e0a\u8a18\u30b3\u30fc\u30c9\u3092\u3001hatena.js\u3068\u3057\u3066\u4fdd\u5b58\u3002\u5b9f\u884c\u3057\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"lang:sh decode:true \" >$ node.io hatena.js<\/pre>\n<p>getHtml\u306e\u623b\u308a\u5024\u304cdom\u30a8\u30ec\u30e1\u30f3\u30c8\u306a\u306e\u3067\u3001jQuery\u306e\u30bb\u30ec\u30af\u30bf\u306b\u4f3c\u305f\u611f\u3058\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u51fa\u305b\u308b\u306e\u304c\u4fbf\u5229\u3002<\/p>\n<p>\u3046\u307e\u304f\u884c\u3063\u305f\u306e\u3067\u3001\u3082\u3046\u3059\u3053\u3057\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3063\u307d\u3044\u3053\u3068\u3092\u3002<br \/>\n\u4e0b\u8a18\u30da\u30fc\u30b8\u304b\u3089\u3001\u653e\u5c04\u7dda\u91cf\u3092\u53d6\u5f97\u3057\u3066postgresql\u306b\u30a4\u30f3\u30b5\u30fc\u30c8\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u66f8\u3044\u3066\u307f\u308b<br \/>\nnode.js+postgresql\u306b\u3064\u3044\u3066\u306f<span class=\"removed_link\" title=\"http:\/\/rm-rforz.blogspot.com\/2011\/04\/nodejs-postgresql.html\">\u3053\u3061\u3089<\/span><\/p>\n<p>\u7fa4\u99ac\u770c\uff1a\u539f\u5b50\u529b\u767a\u96fb\u6240\u4e8b\u6545\u306b\u4fc2\u308b\u672c\u770c\u3067\u306e\u653e\u5c04\u7dda\u91cf\u7b49\u306b\u3064\u3044\u3066<br \/>\n<a href=\"http:\/\/www.pref.gunma.jp\/05\/e0900020.html\">http:\/\/www.pref.gunma.jp\/05\/e0900020.html<\/a><br \/>\n\u4ee5\u4e0b\u30c6\u30b9\u30c8\u7528\u30c6\u30fc\u30d6\u30eb\u306e\u5185\u5bb9<br \/>\n\u30fb\u3081\u3093\u3069\u304f\u3055\u3044\u306e\u3067test_db\u3001gunma_tb\u306f\u5148\u306b\u4f5c\u3063\u3066\u308b<br \/>\n\u30fb\u6e2c\u5b9a\u8005\u3001\u6e2c\u5b9a\u5730\u70b9\u3001\u6e2c\u5b9a\u65e5\u6642\u3001\u6e2c\u5b9a\u5024\u3092\u53d6\u5f97<br \/>\n\u30fbgunma_tb\u306e\u30ab\u30e9\u30e0\u306f\u3000ID,GAUGER, SPOT, DATE, VALUE<br \/>\n\u30fb\u5148\u306e\u30da\u30fc\u30b8\u304c\u6e2c\u5b9a\u5024\u3092\u5168\u89d2\u6570\u5b57\u3067\u66f8\u3044\u3066\u3084\u304c\u308b\u306e\u3067\u3001\u30ab\u30e9\u30e0\u306e\u578b\u306f\u3001ID\u304c\u30b7\u30ea\u30a2\u30eb\u306a\u306e\u3092\u9664\u3044\u3066\u3059\u3079\u3066\u30c6\u30ad\u30b9\u30c8<\/p>\n<pre class=\"lang:js decode:true \" >\r\n    var GAUGER_CELL=5,SPOT_CELL=6,DATE_CELL=7,VALUE_CELL=8\r\n    var nodeio = require('node.io');\r\n    exports.job = new nodeio.Job({\r\n        input:false,\r\n        run:function(){\r\n            var output = [];\r\n            var self = this, url = &quot;http:\/\/www.pref.gunma.jp\/05\/e0900020.html&quot;;\r\n            this.getHtml(url, function(err, $){\r\n                if(err){\r\n                    self.exit(err);\r\n                }else{\r\n                    output = [\r\n                        $('td')[GAUGER_CELL].children[0].raw,\r\n                        $('td')[SPOT_CELL].children[0].raw,\r\n                        $('td')[DATE_CELL].children[0].raw,\r\n                        $('td')[VALUE_CELL].children[0].raw\r\n                    ]\r\n                    var pg = require('pg'); \r\n                    var conString = &quot;tcp:\/\/\uff1c\u30a2\u30ab\u30a6\u30f3\u30c8\uff1e:\uff1c\u30d1\u30b9\u30ef\u30fc\u30c9\uff1e@localhost\/test_db&quot;;\r\n                    var client = new pg.Client(conString);\r\n                    client.connect();\r\n                    client.query(&quot;INSERT INTO gunma_tb(GAUGER, SPOT, DATE, VALUE) values($1, $2, $3, $4)&quot;, output,function(err,result){\r\n                        client.end();\r\n                    });                 \r\n                }\r\n            })\r\n        }\r\n    })<\/pre>\n<p>node.io\u306f\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u4ee5\u5916\u306b\u3082\u3001\u6a19\u6e96\u5165\u51fa\u529b\u3084\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u66f8\u304d\u306a\u3069\u304c\u7c21\u5358\u306b\u6271\u3048\u308b\u306e\u3067\u3001\u3061\u3087\u3063\u3068\u3057\u305f\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u30a2\u30d7\u30ea\u3092node.js\u3067\u66f8\u304f\u306e\u306b\u4fbf\u5229\u305d\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003 node.js\u3067\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\uff08cheeri&hellip;<\/p>\n","protected":false},"author":1,"featured_media":5090,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-19","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/19","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=19"}],"version-history":[{"count":7,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":402,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/19\/revisions\/402"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/5090"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}