数据爬虫,把请求回来的数据组合,并用过cheerio模块筛选,筛选方式跟jquery选择器用法基本相似

    1. const http = require('http')
    2. const https = require('https')
    3. const cheerio = require('cheerio');
    4. function filterData(data) {
    5. let $ = cheerio.load(data)
    6. $('.comment-img-wp img').each((index, el) => {
    7. console.log($(el).attr('data-src'))
    8. })
    9. }
    10. const server = http.createServer((req, res) => {
    11. let data = ''
    12. https.get('https://m.meizu.com', (result) => {
    13. result.on('data', (chunk) => {
    14. data += chunk
    15. })
    16. result.on('end', () => {
    17. filterData(data)
    18. })
    19. })
    20. })
    21. server.listen(2139, () => {
    22. console.log('2139succ')
    23. })