logo科技微讯

微博热搜监测

作者:科技微讯
日期:2021-11-24
📝 笔记
async function app() {
  const url =
    "https://m.weibo.cn/api/container/getIndex?containerid=106003type%3D25%26t%3D3%26disable_hot%3D1%26filter_type%3Drealtimehot";
  const json = await got(url).json();
  let cardsHot = null;

  for (let item of json.data.cards) {
    if (item.title.indexOf("实时热点") >= 0) {
      cardsHot = item;
      break;
    }
  }
  const cards = cardsHot.card_group
    .map((item) => {
      return {
        pic: item.pic, //热搜榜左边的小图标,包括置顶、排序
        icon: item.icon || "", //热搜榜右边的小图标,例如热、新、荐,大部分是没有这个小图标的
        desc: item.desc,
        link: item.scheme,
      };
    })
    .filter((item) => {
      //把置顶的、推荐的过滤掉
      if (item.pic.indexOf("stick") >= 0) {
        return false;
      }
      if (item.icon.indexOf("recommend") >= 0) {
        return false;
      }
      return true;
    })
    .slice(0, 10); //只关注前 10 的热点

  console.log(cards);
}

app();
donation赞赏
thumbsup0
thumbsdown0
暂无评论