0

这段代码有问题。每当我运行它时,它都会显示“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)
})

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

4

0 回答 0