TypeError:调用回调函数时,回调不是函数

时间:2020-07-17 22:30:39

标签: node.js web-scraping callback aliexpress

这段代码有麻烦。每当我运行它时,它都会显示“ TypeError:回调不是函数”。我尝试自己弄清楚,但是运气不高。如果有人可以帮助我,我将不胜感激!

var getPData = require('aliexpress-product-scraper');

function getProducts(ids, data, count, callback) {
    getPData(ids[count]).then(res => {
        data.push({ title: res.title, description: res.description, image: res.images[0] })
        console.log(`[${count}]`)
        count++

        if (count >= ids.length) {
            callback(data)
        }
        else {
            getProducts(ids, data, count)
        }
    })
    .catch(err => console.error(err))
}

getProducts ([
    4000021893815, 33003633828,
    4000525729095, 33058311152,
    32880245829, 4000651037514,
    4000209825247, 4001139242149,
    33035136283, 33003282862,
    33032105966, 33044615891
], [], 0, (data) => {
    console.log(data)
})

该代码的目的是从aliexpress收集有关产品的数据,如果有帮助的话。

0 个答案:

没有答案