【发布时间】:2018-09-12 16:09:49
【问题描述】:
就像我用下面的代码刮了 3 页:
var Xray = require('x-ray');
var x = Xray();
x('https://blog.ycombinator.com/', '.post', [{
title: 'h1 a',
link: '.article-title@href'
}])
.paginate('.nav-previous a@href')
.limit(3)
.write('results.json')
如何报告进度?
我尝试了 .then() 但似乎不起作用。
x('https://blog.ycombinator.com/', '.post', [{
title: 'h1 a',
link: '.article-title@href'
}])
.paginate('.nav-previous a@href')
.limit(3)
.write('results.json')
.then(
//something to report the progression
)
或同样不起作用的回调函数
x('https://blog.ycombinator.com/', '.post', [{
title: 'h1 a',
link: '.article-title@href'
}])(()=>{
//something to report the progress
})
.paginate('.nav-previous a@href')
.limit(3)
.write('results.json')
【问题讨论】:
-
您说“.then”似乎不起作用-您是如何测试它的?在其中添加一个 console.log 看看会发生什么,例如 .then((res) => { console.log(res) }) 等
-
我得到了他的错误:TypeError: x(...).limit(...).paginate(...).write(...).then is not a function跨度>
标签: javascript x-ray