-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.js
45 lines (32 loc) · 1.45 KB
/
results.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var http = require('http');
var jsdom = require('jsdom');
http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
jsdom.env(
"http://www.premierleague.com/en-gb/matchday/results.html?paramComp_100=true¶mSeason=2014-2015&view=.dateSeason",
["http://code.jquery.com/jquery.js"],
function (errors, window) {
var results = [];
window.$("table.contentTable").each(function(i) {
var strDate = window.$(this).find("th").text();
window.$(this).find("tr").each(function(j){
if (window.$(this).find("th").text().length > 0)
return;
if (window.$(this).find("td.rHome")){
var date = new Date(strDate + " " + window.$(this).children("td.time").text() );
var score = window.$.trim(window.$(this).find("td.score").text());
var homeTeam = window.$.trim(window.$(this).find("td.rHome").text());
var awayTeam = window.$.trim(window.$(this).find("td.rAway").text());
var homeScore = score.split(' - ')[0];
var awayScore = score.split(' - ')[1];
var venue = window.$.trim(window.$(this).find("td.location").text());
if (venue)
results.push({ date: date, score: score, homeTeam:homeTeam, awayTeam:awayTeam, homeScore: homeScore, awayScore: awayScore, venue: venue});
}
});
});
res.write(JSON.stringify(results));
res.end();
}
);
}).listen(30000);