爬虫脚本不想用nodejs在控制台上显示链接

Crawler script does not want to display the links on the console with nodejs

我尝试获取每个汽车版本的所有链接。一切顺利,直到第 3 个 "Request",当我 运行 它在控制台中没有显示任何内容。我不知道为什么。你能帮帮我吗?

var request = require('request');
var fetch=require('node-fetch');
var cheerio = require('cheerio');
var url="http://www.auto-selection.com/fiche-technique/alfa-romeo/";
console.log('starting');

request(url, function(err, resp, html) {
  // Si il n'y a pas d'erreur afficher le code html de l'url
  if (!err){
    var $ = cheerio.load(html);
    var link_model = $(".color3 a");
    $(link_model).each(function (i, link) {
        var link_models = $(this).attr('href');

        // console.log(link_models);
        request(link_models, function(err, resp, html){
          if(!err){
              var $= cheerio.load(html);
              var link_model_year = $(".color3 a");
              $(link_model_year).each(function (index, link) {
                  var links_models_years = $(this).attr('href');
                  // console.log(links_models_years);
                  request(links_models_years, function (err,resp,html) {
                      if(!err){
                          var $= cheerio.load(html);
                          var link_model_version = $(".sorting_1 a");
                          $(link_model_version).each(function () {
                              var links_models_versions = $(this).attr('href');
                              console.log(links_models_versions)
                          });

                      }
                  })

              });

          }
        });

    });
  }
});

问题是加载的页面中没有.sorting_1 class - 它是在页面脚本执行后才添加的。但是 cheerio does not produce a visual rendering, apply CSS, load external resources, or execute JavaScript.

因此您需要使用另一种模式来搜索链接。例如:

var link_model_version = $("#AsFTList a");