node.js 抓包微博热搜

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 即可看到效果

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.基础知识 爬虫爬虫,是一种自动获取网页内容的程序,是搜索引擎的重要组成部分,因此搜索引擎优化很大程度上就是针对...
    JunChow520阅读 4,187评论 0 1
  • 1 Node.js模块的实现 之前在网上查阅了许多介绍Node.js的文章,可惜对于Node.js的模块机制大都着...
    zlx_2017阅读 5,205评论 0 1
  • 概要 64学时 3.5学分 章节安排 电子商务网站概况 HTML5+CSS3 JavaScript Node 电子...
    阿啊阿吖丁阅读 13,174评论 0 3
  • 秋日不寒春风短,简衣难赠贴身人。 三尺红台相映月,酒入酣肠两面生。
    舒堇阅读 1,715评论 0 4
  • 文/张又可 节选自张又可散文集《青春的遗嘱》 终年不遇之后,并非所有的眷顾都是仁慈的,并非所有的得到都是幸福的。 ...
    张又可阅读 1,693评论 2 0

友情链接更多精彩内容