数据爬虫,把请求回来的数据组合,并用过cheerio模块筛选,筛选方式跟jquery选择器用法基本相似
const http = require('http')
const https = require('https')
const cheerio = require('cheerio');
function filterData(data) {
let $ = cheerio.load(data)
$('.comment-img-wp img').each((index, el) => {
console.log($(el).attr('data-src'))
})
}
const server = http.createServer((req, res) => {
let data = ''
https.get('https://m.meizu.com', (result) => {
result.on('data', (chunk) => {
data += chunk
})
result.on('end', () => {
filterData(data)
})
})
})
server.listen(2139, () => {
console.log('2139succ')
})