爬虫功能:抓取https://movie.douban.com/chart页面中的数据,求最高分、最低分、平均分。
const fs = require("fs");
const axios = require("axios");
const cheerio = require("cheerio");
axios.get("https://movie.douban.com/chart").then(res=>{
//console.log(res.data)
//fs.writeFileSync("1.html", res.data);
var $ = cheerio.load(res.data); // 把数据结构化
var data = [];
var all = 0;
var min;
var minIndex;
var max;
var maxIndex;
$(".pl2").each(function( ind, el){
var elem = $(el);
var title = elem.children("a").text().split("/")[0].replace(/\n/g, '').replace(/\s/g, '');
var score = Number(elem.find(".rating_nums").text());
if( min === undefined ){
min = score;
}
if( max === undefined ){
max = score;
}
if(