Sunday, 14 May 2017

Can't get all data from list url using javascript for loop

I have an array A[] are list url website. i use cheerio module in nodejs to get dom html. but my code just return a haft of url have data, and other url return nothing. Please help me how to fix it. tks all. This is my code

for (count = 0; count < a.length; count++) {
    stack.push((function(url) {

        return function(callback) {
            request(url, function(error, response, body) {

                // let dom = body
                if (!error) {
                    $ = cheerio.load(body)
                    // console.log('ok')
                    console.log(url)

                } else {
                    console.log('nothing')
                }
                $('.phone_number').each(function() {
                    sdt = $(this).text()
                })
                $('.member').each(function() {
                    email = $(this).text()
                    vl = validateEmail(email)
                    if (vl) {
                        email = $(this).text()
                        email = email.replace(/\s/g, '')
                    } else {
                        email = ' '
                    }
                })
                var sdt,
                    email
                callback(null, sdt, email)
            })
        }
    })(a[count]))

}

// stack.push(getData)
async.parallel(stack, function(err, result) {
    console.log(error)
    console.log(result)
})



via Bi Li

No comments:

Post a Comment