懂得都懂,en…不做过多的介绍
const http = require("http")
const https =require("https")
const cheerio = require('cheerio');
function filterData(data){
const $ = cheerio.load(data);
//.section-item-box是父级的class名称
$(".section-item-box p").each((index,el)=>{
// index是索引
// el是dom元素
console.log($(el).text())
})
}
const server = http.createServer((req,res)=>{
let data = ''
https.get("https://www.meizu.com/",(result)=>{
result.on("data",(chunk)=>{
data += chunk
})
result.on("end",(chunk)=>{
filterData(data)
})
})
})
server.listen(3000,()=>{
console.log("localhost:3000")
})