https实现node的简单爬虫

function crawler_html(charset, url) {

    https.get(url, (res) => {

        let length = 0;
        let arr = [];

        res.on("data", (chunk) => {
            arr.push(chunk);
            length += chunk.length;
        });

        res.on("end", () => {
            let data = Buffer.concat(arr, length);
            console.log(data)
            let change_data = iconv.decode(data, charset);
            console.log(change_data.toString());
        })

    });
}

你可能感兴趣的:(node)