node.js 抓包微博热搜

2019-12-11  本文已影响0人  __小白___

1.需要用到superagent以及cheerio模块 记得安装

const superagent = require("superagent");
const cheerio = require("cheerio");
const exceljs = require("exceljs");
const fs = require("fs");
const testexcel = new exceljs.Workbook();
testexcel.creator = 'test';
testexcel.lastModifiedBy = "test";
testexcel.created = new Date();
testexcel.modified = new Date();
let sheet = testexcel.addWorksheet("测试报表");
let cookies = "PHPSESSID=f2cm3akf9o0hmio87fn5d8p6d3";
superagent.get("http://www.sina.com.cn/mid/search-list.shtml").end((error,res)=>{
  if(error){
    console.log("error",error)
  }
  
  let $ = cheerio.load(res.text);
  // console.log("result",$(".cont"))
   let i=0;
   $(".cont .phblist li.clear").each((index,item)=>{
      i+=1;
      let _this=$(item);
       console.log("id:",Number(index+1),_this.find("a").first().text(),_this.find("a").first().attr("href"),"指数:",_this.find(".exp").first().find("em").first().text()) 
     
   })
   console.log("countTotal",i)
})

2.node serve.js 即可看到效果

上一篇 下一篇

猜你喜欢

热点阅读