WishMeLz

生活其实很有趣

NodeJs抓取页面内容

const cheerio = require('cheerio');
const request = require('request');
let url = 'https://btc.com/'
    request({ url: url, encoding: null }, function (error, response, body) {
        if (!error && response.statusCode == 200) {
            var buf = iconv.decode(body, 'gb2312');//获取内容进行转码
            $ = cheerio.load(buf);
            var pps = $('body > div > div > div:nth-child(3) > div:nth-child(2) > div > div.panel-body > ul:nth-child(1) > li:nth-child(3) > dl > dd > div:nth-child(1) > span:nth-child(2)');
            var pps = pps.html();
           
        }
    });

元素选择:F12 对自己需要获取的元素右键