我想将网站废弃给json,因为我需要来自网站的数据, 我正在关注教程:https://github.com/matthewmueller/x-ray 但只是返回1个数据,我希望返回许多这样的数据:
{
"category": "Fashion",
"data": [
{
"merchant-name": "Centro",
"imageurl": "https://m.bnizona.com/files/1aa0dd2a47c06f4e30d8bc304d9ad535.jpg",
"promo-title": "BNI Shop & Win dengan Kartu Kredit BNI di Centro Dept Store, Parkson Dept Store dan Parkson Gourmetmart",
"valid-until": "valid until 30 November 2017"
},
{
"merchant-name": "Centro",
"imageurl": "https://m.bnizona.com/files/1aa0dd2a47c06f4e30d8bc304d9ad535.jpg",
"promo-title": "BNI Shop & Win dengan Kartu Kredit BNI di Centro Dept Store, Parkson Dept Store dan Parkson Gourmetmart",
"valid-until": "valid until 30 November 2017"
}
]
},
这是我的代码:
var Xray = require('x-ray');
var x = Xray();
// read link
x('https://m.bnizona.com/index.php/category/index/promo', '.menu li', [{ //read list from .menu li
"category":'a',
// "link":'a@href',
"data":
x('a@href', {
"merchant-name" : ".merchant-name",
"imageurl" : "img@src",
"promo-title" : ".promo-title",
"valid-until" : ".valid-until"
}),
}])(function(err, obj){
console.log(obj)
})
// .paginate('.nav-previous a@href')
// .limit(90)
.write('solution.json')