nodejs循环卷曲,异步或阻塞

时间:2018-07-19 12:02:20

标签: node.js

每个请求完成后如何循环卷曲/请求?像php / blocking。 其当前正在使用的循环foreach async-foreach request

我的代码:

forEach(array_lines, function(page_url, index, arr) {
        request(page_url, function (err, resp, body) {
        if (err) {
            console.log("Error!: " + err + " using ("+j+")" + page_url);
            throw err;
        }
        var $ = cheerio.load(body,{ decodeEntities: false,xmlMode: true });

        console.log('page_url: ',page_url);

        build_json.items[j] = {};

        var id = $("#xx").val();
        console.log('id: ',id);
        build_json.items[j].id = id;

        build_json.items[j].source_url = page_url;

        var title = $("h1.title").text();
        console.log('title: ',title);
        build_json.items[j].title = title;
    });
});

0 个答案:

没有答案