-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
39 lines (35 loc) · 1016 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var cheerio = require('cheerio')
var request = require('request')
var Buffer = require('buffer').Buffer
var Iconv = require('iconv').Iconv
function getPage(callback){
var flavorUrl = "http://www.31ice.co.jp/contents/product/flavor/index.html"
request({ url : flavorUrl, encoding :null }, function(err, response, body){
var conv = response.body
var iconv = new Iconv('EUC-JP','UTF-8//TRANSLIT//IGNORE')
conv = iconv.convert(conv)
conv = conv.toString()
//console.log(encoding.Encoding.isEUCJP(response.body))//.join(""));
callback(conv)
})
}
function getFlavor(callback){
getPage(function(body){
callback(null, parseFlavors(body))
})
}
function parseFlavors(html){
var $ = cheerio.load(html)
var names = []
// fravor for month
names.push($("#fomName").text())
// season flavor
$('#seasonFlavorPhoto img').each(function(){
var name = $(this).attr("alt")
names.push(name)
})
return names
}
module.exports = function(callback){
getFlavor(callback)
}