Node.js 更新网页刮板

Node.js 更新网页刮板,node.js,web-scraping,Node.js,Web Scraping,嗨,我终于能够设置我的webscraper并将数据导入我的网页:) 然而,我的网页在3001端口上运行,网页刮板在8080端口上运行,我有点困惑,我怎么能在后台设置一个定时器来更新刮板呢 Index.js var scraper = require(__dirname + '/scripts/scraper.js'); var express = require('express'); var path = require('path'); var app = express(); var M

嗨,我终于能够设置我的webscraper并将数据导入我的网页:)

然而,我的网页在3001端口上运行,网页刮板在8080端口上运行,我有点困惑,我怎么能在后台设置一个定时器来更新刮板呢

Index.js

var scraper = require(__dirname + '/scripts/scraper.js');
var express = require('express');
var path = require('path');
var app = express();

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://127.0.0.1:27017/test";

app.use(express.static(__dirname + '/public'));

// set the view engine to ejs
app.set('view engine', 'ejs');

// index page 
app.get('/', function(req, res) {
   MongoClient.connect(url, function(err, db) {
     if (err) throw err;
     var dbo = db.db("mydb");
     dbo.collection("customers").find({}).toArray(function(err, result) {
       if (err) throw err;
       res.render('pages/index', {
         result: result,
      });
        db.close();
      });
   });  
 });


app.listen(3001);
console.log('navigate to: http://178.62.253.206:3001');
var http = require('http');
var request = require('request');
var cheerio = require('cheerio');
var MongoClient = require('mongodb').MongoClient

http.createServer(function(req, res) {
  request('http://www.xscores.com/soccer', function(error, response,
    html) {
    if (!error && response.statusCode == 200) {
      var $ = cheerio.load(html);
      var list_items = "";
      var arr = [];
      var j = 1;


      // Step1 Get Data
      // Live Matches Even rows
      $('div.match_line.score_row.live_match.e_true ').each(function(i, 
element) {

    // Get Home team and apply changes to it 
    var hteam = $(this).attr('data-home-team');
    var hteam = hteam.toLowerCase();
    var hteam = ucwords(hteam); 
    var hteam = soccer(hteam);

    // Get Away team and apply changes to it 
    var ateam = $(this).attr('data-away-team');
    var ateam = ateam.toLowerCase();
    var ateam = ucwords(ateam); 
    var ateam = soccer(ateam);

    // Get Country and apply changes to it 
    var country = $(this).attr('data-country-name');
    var country = country.toLowerCase();
    var country = ucwords(country); 

    // Get League and apply changes to it 
    var league = $(this).attr('data-league-name');
    var league = league.toLowerCase();
    var league = ucwords(league); 

    // Adjust the KO Clock
    var Kickoff = $(this).attr('data-ko');
    var Kickoff = subtracthour(Kickoff);

    arr.push({
      hteam: hteam,
      ateam: ateam,
      j: j,
      statustype: $(this).attr('data-statustype'),
      country: country,
      league: league,
      Kickoff: Kickoff
    });
    j = j + 2;
    //list_items += "<li>" + a + "</li>";
    //console.log(arr.length);
  });
  var j = 2;


  // Step 1.5 Get Data
  // Live Matches, Odd rows
  $('div.match_line.score_row.live_match.o_true ').each(function(i, element) 
{
    // Get Home team and apply changes to it 
    var hteam = $(this).attr('data-home-team');
    var hteam = hteam.toLowerCase();
    var hteam = ucwords(hteam); 
    var hteam = soccer(hteam);

    // Get Away team and apply changes to it 
    var ateam = $(this).attr('data-away-team');
    var ateam = ateam.toLowerCase();
    var ateam = ucwords(ateam); 
    var ateam = soccer(ateam);

    // Get Country and apply changes to it 
    var country = $(this).attr('data-country-name');
    var country = country.toLowerCase();
    var country = ucwords(country); 

    // Get League and apply changes to it 
    var league = $(this).attr('data-league-name');
    var league = league.toLowerCase();
    var league = ucwords(league); 

    // Adjust the KO Clock
    var Kickoff = $(this).attr('data-ko');
    var Kickoff = subtracthour(Kickoff);

    arr.push({
      hteam: hteam,
      ateam: ateam,
      j: j,
      statustype: $(this).attr('data-statustype'),
      country: country,
      league: league,
      Kickoff: Kickoff
    });
    j = j + 2;
    //list_items += "<li>" + b + "</li>";
    //console.log(arr.length);
  });

  //Sort the data
  arr.sort(function(a, b) {
    return a.j - b.j
  })

  //Calculate which row to resume (odd/even)
  if (isEven(arr.length) == true){
      //console.log("Even Number");
      var j = arr.length + 1;
      var x = arr.length + 2;
  } else {
      //console.log("Odd Number");
      var j = arr.length + 2;
      var x = arr.length + 1;
  }

  //  Step 2 Get Data
  //  "sched" games from even rows
  $('div.match_line.score_row.other_match.e_true').each(function(i, element) 
{

    // Get Home team and apply changes to it 
    var hteam = $(this).attr('data-home-team');
    var hteam = hteam.toLowerCase();
    var hteam = ucwords(hteam); 
    var hteam = soccer(hteam);

    // Get Away team and apply changes to it 
    var ateam = $(this).attr('data-away-team');
    var ateam = ateam.toLowerCase();
    var ateam = ucwords(ateam); 
    var ateam = soccer(ateam);

    // Get Country and apply changes to it 
    var country = $(this).attr('data-country-name');
    var country = country.toLowerCase();
    var country = ucwords(country); 

    // Get League and apply changes to it 
    var league = $(this).attr('data-league-name');
    var league = league.toLowerCase();
    var league = ucwords(league); 

    // Adjust the KO Clock
    var Kickoff = $(this).attr('data-ko');
    var Kickoff = subtracthour(Kickoff);

    // Get GameStatus
    var gs = $(this).attr('data-statustype');

    if (gs != "sched") { return false;  }
    arr.push({
      hteam: hteam,
      ateam: ateam,
      j: j,
      statustype: $(this).attr('data-statustype'),
      country: country,
      league: league,
      Kickoff: Kickoff
    });
    j = j + 2;

    //list_items += "<li>" + a + "</li>";
    //console.log(arr.length);
  });

   //  Step 2.5 Get Data
  //Scrape "sched" games from odd rows
  var j = x
  $('div.match_line.score_row.other_match.o_true').each(function(i, element) {

    // Get Home team and apply changes to it 
    var hteam = $(this).attr('data-home-team');
    var hteam = hteam.toLowerCase();
    var hteam = ucwords(hteam); 
    var hteam = soccer(hteam);

     // Get Away team and apply changes to it 
    var ateam = $(this).attr('data-away-team');
    var ateam = ateam.toLowerCase();
    var ateam = ucwords(ateam); 
    var ateam = soccer(ateam);

    // Get Country and apply changes to it 
    var country = $(this).attr('data-country-name');
    var country = country.toLowerCase();
    var country = ucwords(country); 

    // Get League and apply changes to it 
    var league = $(this).attr('data-league-name');
    var league = league.toLowerCase();
    var league = ucwords(league); 

    // Get GameStatus
    var gs = $(this).attr('data-statustype');

    // Adjust the KO Clock
    var Kickoff = $(this).attr('data-ko');
    var Kickoff = subtracthour(Kickoff);

    if (gs != "sched") { return false; }
    arr.push({
      hteam: hteam,
      ateam: ateam,
      j: j,
      statustype: $(this).attr('data-statustype'),
      country: country,
      league: league,
      Kickoff: Kickoff
    });
    j = j + 2;
    //list_items += "<li>" + a + "</li>";
    //console.log(arr.length);
  });

  //Sort the data we fetched
  arr.sort(function(a, b) {
    return a.j - b.j
  })

  //Calculate which row to resume (odd/even)
  if (isEven(arr.length) == true){
      //console.log("Even Number");
      var j = arr.length + 2;
      var x = arr.length + 1;
  } else {
      //console.log("Odd Number");
      var j = arr.length + 1;
      var x = arr.length + 2;
  }


  // - Step 3 Get Data
  // - Scrape Finished matches games from even rows
  $('div.match_line.score_row.other_match.e_true').each(function(i, element) {
    // Get Home team and apply changes to it 
    var hteam = $(this).attr('data-home-team');
    var hteam = hteam.toLowerCase();
    var hteam = ucwords(hteam); 
    var hteam = soccer(hteam);

    // Get Away team and apply changes to it 
    var ateam = $(this).attr('data-away-team');
    var ateam = ateam.toLowerCase();
    var ateam = ucwords(ateam); 
    var ateam = soccer(ateam);

    // Get Country and apply changes to it 
    var country = $(this).attr('data-country-name');
    var country = country.toLowerCase();
    var country = ucwords(country); 

    // Get League and apply changes to it 
    var league = $(this).attr('data-league-name');
    var league = league.toLowerCase();
    var league = ucwords(league); 

    // Adjust the KO Clock
    var Kickoff = $(this).attr('data-ko');
    var Kickoff = subtracthour(Kickoff);

    // Get GameStatus
    var gs = $(this).attr('data-statustype');

    if (gs != 'sched'|| $(this).attr('data-ftr') ==  'true') { 
      arr.push({
        hteam: hteam,
        ateam: ateam,
        j: j,
        statustype: $(this).attr('data-statustype'),
        country: country,
        league: league,
        Kickoff: Kickoff
      });
      j = j + 2;
    }
  });

  // - Step 3.5 Get Data
  // - Scrape Finished matches games from even rows
  var j = x
  $('div.match_line.score_row.other_match.o_true').each(function(i, element) {

    // Get Home team and apply changes to it 
    var hteam = $(this).attr('data-home-team');
    var hteam = hteam.toLowerCase();
    var hteam = ucwords(hteam); 
    var hteam = soccer(hteam);

    // Get Away team and apply changes to it 
    var ateam = $(this).attr('data-away-team');
    var ateam = ateam.toLowerCase();
    var ateam = ucwords(ateam); 
    var ateam = soccer(ateam);

    // Get Country and apply changes to it 
    var country = $(this).attr('data-country-name');
    var country = country.toLowerCase();
    var country = ucwords(country); 

    // Get League and apply changes to it 
    var league = $(this).attr('data-league-name');
    var league = league.toLowerCase();
    var league = ucwords(league); 

    // Adjust the KO Clock
    var Kickoff = $(this).attr('data-ko');
    var Kickoff = subtracthour(Kickoff);

    // Get GameStatus
    var gs = $(this).attr('data-statustype');

    if (gs != 'sched'|| $(this).attr('data-ftr') ==  'true') { 
      arr.push({
        hteam: hteam,
        ateam: ateam,
        j: j,
        statustype: $(this).attr('data-statustype'),
        country: country,
        league: league,
        Kickoff: Kickoff
      });
      j = j + 2
    }
  });

  //Sort the data
  arr.sort(function(a, b) {
    return a.j - b.j
  })

  //Output from the array to html on server page
  var arrayLength = arr.length;
  var columns = ""
  for (var i = 0; i < arrayLength; i++) {
    let row = "" 

    if (i < arr.length) {
        row += "<td>" + arr[i].j + "</td>"
        row += "<td>" + arr[i].Kickoff + "</td>"
        row += "<td>" + arr[i].statustype + "</td>"
        row += "<td>" + arr[i].country + "</td>"
        row += "<td>" + arr[i].league + "</td>"
        row += "<td>" + arr[i].hteam + "</td>"
        row += "<td>" + arr[i].ateam + "</td>"
    } 
    columns += "<tr>" + row + "</tr>";
  }



  //var html = "<table><tr>" + columns + "</tr></table>"
  //res.writeHead(200, {
  //  'Content-Type': 'text/html'
  //});
  //res.end(html);

  // MongoDataBase
  MongoClient.connect('mongodb://127.0.0.1:27017/test', function (err, db) {
  if (err) throw err;
    var dbo = db.db("mydb");

    // Delete old records
    dbo.dropCollection("customers", function(err, delOK) {
      if (err) throw err;
      if (delOK) console.log("Collection deleted");
    });

    // Add new records
    dbo.collection("customers").insertMany(arr, function(err, res) {
    if (err) throw err;
      console.log("Collection created!");
      db.close();
    });
  });
  // End MongoDataBase
  //console.log(arr.length);
}
});

}).listen(8080);
console.log('Server is running at http://178.62.253.206:8080/');


function isEven(n) {
  return n == parseFloat(n)? !(n%2) : void 0;
}
function ucwords (str) {
   return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
    return $1.toUpperCase();
});
}

function subtracthour(str) {
   var m = str.slice(3, 5);
   var h = str.slice(0, 2);

   if (h == '00') { h = "24"; }
   var h = Number(h) - Number(1);
   if (h <= 9) { h = "0" + h; }

  var y = h + ":" + m;
  return y;    // Note this was return str
}
function soccer(str) {
  var x = str
  var x = x.replace(" Ff", " FF");
 return x    
}
它现在的工作方式是,我需要导航到更新web scraper

我希望在后台悄悄地更新刮板

scraper.js

var scraper = require(__dirname + '/scripts/scraper.js');
var express = require('express');
var path = require('path');
var app = express();

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://127.0.0.1:27017/test";

app.use(express.static(__dirname + '/public'));

// set the view engine to ejs
app.set('view engine', 'ejs');

// index page 
app.get('/', function(req, res) {
   MongoClient.connect(url, function(err, db) {
     if (err) throw err;
     var dbo = db.db("mydb");
     dbo.collection("customers").find({}).toArray(function(err, result) {
       if (err) throw err;
       res.render('pages/index', {
         result: result,
      });
        db.close();
      });
   });  
 });


app.listen(3001);
console.log('navigate to: http://178.62.253.206:3001');
var http = require('http');
var request = require('request');
var cheerio = require('cheerio');
var MongoClient = require('mongodb').MongoClient

http.createServer(function(req, res) {
  request('http://www.xscores.com/soccer', function(error, response,
    html) {
    if (!error && response.statusCode == 200) {
      var $ = cheerio.load(html);
      var list_items = "";
      var arr = [];
      var j = 1;


      // Step1 Get Data
      // Live Matches Even rows
      $('div.match_line.score_row.live_match.e_true ').each(function(i, 
element) {

    // Get Home team and apply changes to it 
    var hteam = $(this).attr('data-home-team');
    var hteam = hteam.toLowerCase();
    var hteam = ucwords(hteam); 
    var hteam = soccer(hteam);

    // Get Away team and apply changes to it 
    var ateam = $(this).attr('data-away-team');
    var ateam = ateam.toLowerCase();
    var ateam = ucwords(ateam); 
    var ateam = soccer(ateam);

    // Get Country and apply changes to it 
    var country = $(this).attr('data-country-name');
    var country = country.toLowerCase();
    var country = ucwords(country); 

    // Get League and apply changes to it 
    var league = $(this).attr('data-league-name');
    var league = league.toLowerCase();
    var league = ucwords(league); 

    // Adjust the KO Clock
    var Kickoff = $(this).attr('data-ko');
    var Kickoff = subtracthour(Kickoff);

    arr.push({
      hteam: hteam,
      ateam: ateam,
      j: j,
      statustype: $(this).attr('data-statustype'),
      country: country,
      league: league,
      Kickoff: Kickoff
    });
    j = j + 2;
    //list_items += "<li>" + a + "</li>";
    //console.log(arr.length);
  });
  var j = 2;


  // Step 1.5 Get Data
  // Live Matches, Odd rows
  $('div.match_line.score_row.live_match.o_true ').each(function(i, element) 
{
    // Get Home team and apply changes to it 
    var hteam = $(this).attr('data-home-team');
    var hteam = hteam.toLowerCase();
    var hteam = ucwords(hteam); 
    var hteam = soccer(hteam);

    // Get Away team and apply changes to it 
    var ateam = $(this).attr('data-away-team');
    var ateam = ateam.toLowerCase();
    var ateam = ucwords(ateam); 
    var ateam = soccer(ateam);

    // Get Country and apply changes to it 
    var country = $(this).attr('data-country-name');
    var country = country.toLowerCase();
    var country = ucwords(country); 

    // Get League and apply changes to it 
    var league = $(this).attr('data-league-name');
    var league = league.toLowerCase();
    var league = ucwords(league); 

    // Adjust the KO Clock
    var Kickoff = $(this).attr('data-ko');
    var Kickoff = subtracthour(Kickoff);

    arr.push({
      hteam: hteam,
      ateam: ateam,
      j: j,
      statustype: $(this).attr('data-statustype'),
      country: country,
      league: league,
      Kickoff: Kickoff
    });
    j = j + 2;
    //list_items += "<li>" + b + "</li>";
    //console.log(arr.length);
  });

  //Sort the data
  arr.sort(function(a, b) {
    return a.j - b.j
  })

  //Calculate which row to resume (odd/even)
  if (isEven(arr.length) == true){
      //console.log("Even Number");
      var j = arr.length + 1;
      var x = arr.length + 2;
  } else {
      //console.log("Odd Number");
      var j = arr.length + 2;
      var x = arr.length + 1;
  }

  //  Step 2 Get Data
  //  "sched" games from even rows
  $('div.match_line.score_row.other_match.e_true').each(function(i, element) 
{

    // Get Home team and apply changes to it 
    var hteam = $(this).attr('data-home-team');
    var hteam = hteam.toLowerCase();
    var hteam = ucwords(hteam); 
    var hteam = soccer(hteam);

    // Get Away team and apply changes to it 
    var ateam = $(this).attr('data-away-team');
    var ateam = ateam.toLowerCase();
    var ateam = ucwords(ateam); 
    var ateam = soccer(ateam);

    // Get Country and apply changes to it 
    var country = $(this).attr('data-country-name');
    var country = country.toLowerCase();
    var country = ucwords(country); 

    // Get League and apply changes to it 
    var league = $(this).attr('data-league-name');
    var league = league.toLowerCase();
    var league = ucwords(league); 

    // Adjust the KO Clock
    var Kickoff = $(this).attr('data-ko');
    var Kickoff = subtracthour(Kickoff);

    // Get GameStatus
    var gs = $(this).attr('data-statustype');

    if (gs != "sched") { return false;  }
    arr.push({
      hteam: hteam,
      ateam: ateam,
      j: j,
      statustype: $(this).attr('data-statustype'),
      country: country,
      league: league,
      Kickoff: Kickoff
    });
    j = j + 2;

    //list_items += "<li>" + a + "</li>";
    //console.log(arr.length);
  });

   //  Step 2.5 Get Data
  //Scrape "sched" games from odd rows
  var j = x
  $('div.match_line.score_row.other_match.o_true').each(function(i, element) {

    // Get Home team and apply changes to it 
    var hteam = $(this).attr('data-home-team');
    var hteam = hteam.toLowerCase();
    var hteam = ucwords(hteam); 
    var hteam = soccer(hteam);

     // Get Away team and apply changes to it 
    var ateam = $(this).attr('data-away-team');
    var ateam = ateam.toLowerCase();
    var ateam = ucwords(ateam); 
    var ateam = soccer(ateam);

    // Get Country and apply changes to it 
    var country = $(this).attr('data-country-name');
    var country = country.toLowerCase();
    var country = ucwords(country); 

    // Get League and apply changes to it 
    var league = $(this).attr('data-league-name');
    var league = league.toLowerCase();
    var league = ucwords(league); 

    // Get GameStatus
    var gs = $(this).attr('data-statustype');

    // Adjust the KO Clock
    var Kickoff = $(this).attr('data-ko');
    var Kickoff = subtracthour(Kickoff);

    if (gs != "sched") { return false; }
    arr.push({
      hteam: hteam,
      ateam: ateam,
      j: j,
      statustype: $(this).attr('data-statustype'),
      country: country,
      league: league,
      Kickoff: Kickoff
    });
    j = j + 2;
    //list_items += "<li>" + a + "</li>";
    //console.log(arr.length);
  });

  //Sort the data we fetched
  arr.sort(function(a, b) {
    return a.j - b.j
  })

  //Calculate which row to resume (odd/even)
  if (isEven(arr.length) == true){
      //console.log("Even Number");
      var j = arr.length + 2;
      var x = arr.length + 1;
  } else {
      //console.log("Odd Number");
      var j = arr.length + 1;
      var x = arr.length + 2;
  }


  // - Step 3 Get Data
  // - Scrape Finished matches games from even rows
  $('div.match_line.score_row.other_match.e_true').each(function(i, element) {
    // Get Home team and apply changes to it 
    var hteam = $(this).attr('data-home-team');
    var hteam = hteam.toLowerCase();
    var hteam = ucwords(hteam); 
    var hteam = soccer(hteam);

    // Get Away team and apply changes to it 
    var ateam = $(this).attr('data-away-team');
    var ateam = ateam.toLowerCase();
    var ateam = ucwords(ateam); 
    var ateam = soccer(ateam);

    // Get Country and apply changes to it 
    var country = $(this).attr('data-country-name');
    var country = country.toLowerCase();
    var country = ucwords(country); 

    // Get League and apply changes to it 
    var league = $(this).attr('data-league-name');
    var league = league.toLowerCase();
    var league = ucwords(league); 

    // Adjust the KO Clock
    var Kickoff = $(this).attr('data-ko');
    var Kickoff = subtracthour(Kickoff);

    // Get GameStatus
    var gs = $(this).attr('data-statustype');

    if (gs != 'sched'|| $(this).attr('data-ftr') ==  'true') { 
      arr.push({
        hteam: hteam,
        ateam: ateam,
        j: j,
        statustype: $(this).attr('data-statustype'),
        country: country,
        league: league,
        Kickoff: Kickoff
      });
      j = j + 2;
    }
  });

  // - Step 3.5 Get Data
  // - Scrape Finished matches games from even rows
  var j = x
  $('div.match_line.score_row.other_match.o_true').each(function(i, element) {

    // Get Home team and apply changes to it 
    var hteam = $(this).attr('data-home-team');
    var hteam = hteam.toLowerCase();
    var hteam = ucwords(hteam); 
    var hteam = soccer(hteam);

    // Get Away team and apply changes to it 
    var ateam = $(this).attr('data-away-team');
    var ateam = ateam.toLowerCase();
    var ateam = ucwords(ateam); 
    var ateam = soccer(ateam);

    // Get Country and apply changes to it 
    var country = $(this).attr('data-country-name');
    var country = country.toLowerCase();
    var country = ucwords(country); 

    // Get League and apply changes to it 
    var league = $(this).attr('data-league-name');
    var league = league.toLowerCase();
    var league = ucwords(league); 

    // Adjust the KO Clock
    var Kickoff = $(this).attr('data-ko');
    var Kickoff = subtracthour(Kickoff);

    // Get GameStatus
    var gs = $(this).attr('data-statustype');

    if (gs != 'sched'|| $(this).attr('data-ftr') ==  'true') { 
      arr.push({
        hteam: hteam,
        ateam: ateam,
        j: j,
        statustype: $(this).attr('data-statustype'),
        country: country,
        league: league,
        Kickoff: Kickoff
      });
      j = j + 2
    }
  });

  //Sort the data
  arr.sort(function(a, b) {
    return a.j - b.j
  })

  //Output from the array to html on server page
  var arrayLength = arr.length;
  var columns = ""
  for (var i = 0; i < arrayLength; i++) {
    let row = "" 

    if (i < arr.length) {
        row += "<td>" + arr[i].j + "</td>"
        row += "<td>" + arr[i].Kickoff + "</td>"
        row += "<td>" + arr[i].statustype + "</td>"
        row += "<td>" + arr[i].country + "</td>"
        row += "<td>" + arr[i].league + "</td>"
        row += "<td>" + arr[i].hteam + "</td>"
        row += "<td>" + arr[i].ateam + "</td>"
    } 
    columns += "<tr>" + row + "</tr>";
  }



  //var html = "<table><tr>" + columns + "</tr></table>"
  //res.writeHead(200, {
  //  'Content-Type': 'text/html'
  //});
  //res.end(html);

  // MongoDataBase
  MongoClient.connect('mongodb://127.0.0.1:27017/test', function (err, db) {
  if (err) throw err;
    var dbo = db.db("mydb");

    // Delete old records
    dbo.dropCollection("customers", function(err, delOK) {
      if (err) throw err;
      if (delOK) console.log("Collection deleted");
    });

    // Add new records
    dbo.collection("customers").insertMany(arr, function(err, res) {
    if (err) throw err;
      console.log("Collection created!");
      db.close();
    });
  });
  // End MongoDataBase
  //console.log(arr.length);
}
});

}).listen(8080);
console.log('Server is running at http://178.62.253.206:8080/');


function isEven(n) {
  return n == parseFloat(n)? !(n%2) : void 0;
}
function ucwords (str) {
   return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
    return $1.toUpperCase();
});
}

function subtracthour(str) {
   var m = str.slice(3, 5);
   var h = str.slice(0, 2);

   if (h == '00') { h = "24"; }
   var h = Number(h) - Number(1);
   if (h <= 9) { h = "0" + h; }

  var y = h + ":" + m;
  return y;    // Note this was return str
}
function soccer(str) {
  var x = str
  var x = x.replace(" Ff", " FF");
 return x    
}
var http=require('http');
var请求=要求(“请求”);
var cheerio=需要('cheerio');
var MongoClient=require('mongodb')。MongoClient
http.createServer(函数(req,res){
请求('http://www.xscores.com/soccer,函数(错误、响应、,
(html){
如果(!error&&response.statusCode==200){
var$=cheerio.load(html);
var列表_项=”;
var-arr=[];
var j=1;
//步骤1获取数据
//实时匹配偶数行
$(“div.match\u line.score\u row.live\u match.e\u true”)。每个函数(i,
元素){
//获取主团队并对其应用更改
var hteam=$(this.attr('data-home-team');
var hteam=hteam.toLowerCase();
var hteam=ucwords(hteam);
var hteam=足球(hteam);
//离开团队并对其应用更改
var ateam=$(this.attr('data-away-team');
var ateam=ateam.toLowerCase();
var ateam=ucwords(ateam);
var ateam=足球(ateam);
//获取国家/地区并对其应用更改
var country=$(this.attr('data-country-name');
var country=country.toLowerCase();
var country=ucwords(国家);
//获取联盟并对其应用更改
var-league=$(this.attr('data-league-name');
var league=league.toLowerCase();
var-league=ucwords(league);
//调整时钟
var Kickoff=$(this.attr('data-ko');
var启动=小时(启动);
arr.push({
hteam:hteam,
阿泰姆:阿泰姆,
j:j,
statustype:$(this.attr('data-statustype'),
国家:国家,,
联盟:联盟,,
开球:开球
});
j=j+2;
//列出项目+=“
  • ”+a+“
  • ”; //控制台日志(arr.length); }); var j=2; //步骤1.5获取数据 //现场比赛,奇数排 $('div.match\u line.score\u row.live\u match.o\u true')。每个(函数(i,元素) { //获取主团队并对其应用更改 var hteam=$(this.attr('data-home-team'); var hteam=hteam.toLowerCase(); var hteam=ucwords(hteam); var hteam=足球(hteam); //离开团队并对其应用更改 var ateam=$(this.attr('data-away-team'); var ateam=ateam.toLowerCase(); var ateam=ucwords(ateam); var ateam=足球(ateam); //获取国家/地区并对其应用更改 var country=$(this.attr('data-country-name'); var country=country.toLowerCase(); var country=ucwords(国家); //获取联盟并对其应用更改 var-league=$(this.attr('data-league-name'); var league=league.toLowerCase(); var-league=ucwords(league); //调整时钟 var Kickoff=$(this.attr('data-ko'); var启动=小时(启动); arr.push({ hteam:hteam, 阿泰姆:阿泰姆, j:j, statustype:$(this.attr('data-statustype'), 国家:国家,, 联盟:联盟,, 开球:开球 }); j=j+2; //列出项目+=“
  • ”+b+“
  • ”; //控制台日志(arr.length); }); //对数据进行排序 arr.sort(函数(a,b){ 返回a.j-b.j }) //计算要恢复的行(奇数/偶数) 如果(isEven(arr.length)==真){ //控制台日志(“偶数”); var j=阵列长度+1; var x=阵列长度+2; }否则{ //控制台日志(“奇数”); var j=阵列长度+2; var x=阵列长度+1; } //步骤2获取数据 //从偶数行开始的“sched”游戏 $('div.match\u line.score\u row.other\u match.e\u true')。每个(函数(i,元素) { //获取主团队并对其应用更改 var hteam=$(this.attr('data-home-team'); var hteam=hteam.toLowerCase(); var hteam=ucwords(hteam); var hteam=足球(hteam); //离开团队并对其应用更改 var ateam=$(this.attr('data-away-team'); var ateam=ateam.toLowerCase(); var ateam=ucwords(ateam); var ateam=足球(ateam); //获取国家/地区并对其应用更改 var country=$(this.attr('data-country-name'); var country=country.toLowerCase(); var country=ucwords(国家); //获取联盟并对其应用更改 var-league=$(this.attr('data-league-name'); var league=league.toLowerCase(); var-league=ucwords(league); //调整时钟 var Kickoff=$(this.attr('data-ko'); var启动=小时(启动); //获取游戏状态 var gs=$(this.attr('data-statustype'); 如果(gs!=“sched”){return false;} arr.push({ hteam:hteam, 阿泰姆:阿泰姆, j:j, statustype:$(this.attr('data-statustype'), 国家:国家,, 联盟:联盟,, 开球:开球 }); j=j+2; //列出项目+=“
  • ”+a+“
  • ”; //控制台日志(arr.length); }); //步骤2.5获取数据 //从奇数行中删除“sched”游戏 var j=x $('div.match\u line.score\u row.other\u match.o\u true')。每个(函数(i,元素){ //获取主团队并对其应用更改 var hteam=$(this.attr('data-home-team'); var hteam=hteam.toLowerCase(); var hteam=ucwords(hteam); var hteam=足球(hteam); //离开团队并对其应用更改 var ateam=$(this.attr('data-away-team'); var ateam=ateam.toLowerCase(); var ateam=ucwords(ateam); var ateam=足球(ateam); //获取国家/地区并对其应用更改 var country=$(this.attr('data-country-name'); var country=country.toLowerCase(); var country=ucwords(国家); //获取联盟并对其应用更改 var联盟=