爬虫
const axios=require("axios")
//同步异步 同步有 Sync
const.fs=require("fs")
//搜索内容 需要安装cheerio 命令npm i cheerio --save
const.cheerio=require("cheerio")
axios.get('这是你要爬虫的网址').then(res=>{
const $ =cheerio.load(res.data);
const objs=[];
//xxx是你想要的内容的id
//对这个进行循环获取内容
$("xxxx").each(function(){
var obj={};
//obj.xxx 命名
//text 文本
obj.title=$(this).find('xx').text();
obj.content=$(this).find('xx').text();
console.log(obj);
//push进去
objs.push(obj)
});
//完成后写入一个文件
//JSON.stringfy 将一个 JavaScript 对象或值转换为 JSON 字符串
fs.writeFileSync('xxx自定义文件的内容',JSON.stringfy(objs))
})