Skip to content

Commit 89b766b

Browse files
author
codebasics
committed
added data collectors
1 parent 905f2d5 commit 89b766b

File tree

4 files changed

+376
-0
lines changed

4 files changed

+376
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* -------------- STAGE 1 ------------ */
2+
3+
//------- 1.a Interaction Code ------ //
4+
navigate('https://stats.espncricinfo.com/ci/engine/records/team/match_results.html?id=14450;type=tournament');
5+
6+
7+
let links = parse().match_summary_links;
8+
for(let i of links) {
9+
next_stage({url: i})
10+
}
11+
12+
//------- 1.b Parser Code ------------//
13+
let links = []
14+
const allRows = $('table.engineTable > tbody > tr.data1');
15+
allRows.each((index, element) => {
16+
const tds = $(element).find('td');
17+
const rowURL = "https://www.espncricinfo.com" +$(tds[6]).find('a').attr('href');
18+
links.push(rowURL);
19+
})
20+
return {
21+
'match_summary_links': links
22+
};
23+
24+
/* -------------- STAGE 2 ------------ */
25+
26+
//------- 2.a Interaction Code ------ //
27+
navigate(input.url);
28+
collect(parse());
29+
30+
//------- 2.b Parser Code ------------//
31+
var match = $('div').filter(function(){
32+
return $(this)
33+
.find('span > span > span').text() === String("Match Details")
34+
}).siblings()
35+
team1 = $(match.eq(0)).find('span > span > span').text()
36+
team2 = $(match.eq(1)).find('span > span > span').text()
37+
matchInfo = team1.replace(" Innings", "") + ' Vs ' + team2.replace(" Innings", "")
38+
39+
var tables = $('div > table.ci-scorecard-table');
40+
var firstInningRows = $(tables.eq(0)).find('tbody > tr').filter(function(index, element){
41+
return $(this).find("td").length >= 8
42+
})
43+
44+
var secondInningsRows = $(tables.eq(1)).find('tbody > tr').filter(function(index, element){
45+
return $(this).find("td").length >= 8
46+
});
47+
48+
49+
var battingSummary = []
50+
firstInningRows.each((index, element) => {
51+
var tds = $(element).find('td');
52+
battingSummary.push({
53+
"match": matchInfo,
54+
"team_innings": team1,
55+
"batting_pos": index+1,
56+
"batsman_name": $(tds.eq(0)).find('a > span > span').text().replace(' ', ''),
57+
"dismissal": $(tds.eq(1)).find('span > span').text(),
58+
"run": $(tds.eq(2)).find('strong').text(),
59+
"ball": $(tds.eq(3)).text(),
60+
"4s": $(tds.eq(5)).text(),
61+
"6s": $(tds.eq(6)).text(),
62+
"SR": $(tds.eq(7)).text()
63+
});
64+
});
65+
66+
secondInningsRows.each((index, element) => {
67+
var tds = $(element).find('td');
68+
battingSummary.push({
69+
"match": matchInfo,
70+
"team_innings": team2,
71+
"batting_pos": index+1,
72+
"batsman_name": $(tds.eq(0)).find('a > span > span').text().replace(' ', ''),
73+
"dismissal": $(tds.eq(1)).find('span > span').text(),
74+
"run": $(tds.eq(2)).find('strong').text(),
75+
"ball": $(tds.eq(3)).text(),
76+
"4s": $(tds.eq(5)).text(),
77+
"6s": $(tds.eq(6)).text(),
78+
"SR": $(tds.eq(7)).text()
79+
});
80+
});
81+
82+
return {"batting_summary": battingSummary}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* -------------- STAGE 1 ------------ */
2+
3+
//------- 1.a Interaction Code ------ //
4+
navigate('https://stats.espncricinfo.com/ci/engine/records/team/match_results.html?id=14450;type=tournament');
5+
6+
7+
let links = parse().players_links;
8+
for(let i of links) {
9+
next_stage({url: i})
10+
}
11+
12+
//------- 1.b Parser Code ------------//
13+
let links = []
14+
const allRows = $('table.engineTable > tbody > tr.data1');
15+
allRows.each((index, element) => {
16+
const tds = $(element).find('td');
17+
const rowURL = "https://www.espncricinfo.com" +$(tds[6]).find('a').attr('href');
18+
links.push(rowURL);
19+
})
20+
return {
21+
'players_links': links
22+
};
23+
24+
/* -------------- STAGE 2 ------------ */
25+
26+
//------- 2.a Interaction Code ------ //
27+
navigate(input.url);
28+
collect(parse());
29+
30+
//---------- 2.b Parser Code ---------//
31+
var match = $('div').filter(function(){
32+
return $(this)
33+
.find('span > span > span').text() === String("Match Details")
34+
}).siblings()
35+
team1 = $(match.eq(0)).find('span > span > span').text()
36+
team2 = $(match.eq(1)).find('span > span > span').text()
37+
matchInfo = team1.replace(" Innings", "") + ' Vs ' + team2.replace(" Innings", "")
38+
39+
var tables = $('div > table.ds-table');
40+
var firstInningRows = $(tables.eq(1)).find('tbody > tr').filter(function(index, element){
41+
return $(this).find("td").length >= 11
42+
})
43+
44+
var secondInningsRows = $(tables.eq(3)).find('tbody > tr').filter(function(index, element){
45+
return $(this).find("td").length >= 11
46+
});
47+
48+
49+
var bowlingSummary = []
50+
firstInningRows.each((index, element) => {
51+
var tds = $(element).find('td');
52+
bowlingSummary.push({
53+
"match": matchInfo,
54+
"bowling_team": team2.replace(" Innings", ""),
55+
"bowler_name": $(tds.eq(0)).find('a > span').text().replace(' ', ''),
56+
"overs": $(tds.eq(1)).text(),
57+
"maiden": $(tds.eq(2)).text(),
58+
"runs": $(tds.eq(3)).text(),
59+
"wickets": $(tds.eq(4)).text(),
60+
"economy": $(tds.eq(5)).text(),
61+
"0s": $(tds.eq(6)).text(),
62+
"4s": $(tds.eq(7)).text(),
63+
"6s": $(tds.eq(8)).text(),
64+
"wides": $(tds.eq(9)).text(),
65+
"no_balls": $(tds.eq(10)).text()
66+
});
67+
});
68+
69+
secondInningsRows.each((index, element) => {
70+
var tds = $(element).find('td');
71+
bowlingSummary.push({
72+
"match": matchInfo,
73+
"bowling_team": team1.replace(" Innings", ""),
74+
"bowler_name": $(tds.eq(0)).find('a > span').text().replace(' ', ''),
75+
"overs": $(tds.eq(1)).text(),
76+
"maiden": $(tds.eq(2)).text(),
77+
"runs": $(tds.eq(3)).text(),
78+
"wickets": $(tds.eq(4)).text(),
79+
"economy": $(tds.eq(5)).text(),
80+
"0s": $(tds.eq(6)).text(),
81+
"4s": $(tds.eq(7)).text(),
82+
"6s": $(tds.eq(8)).text(),
83+
"wides": $(tds.eq(9)).text(),
84+
"no_balls": $(tds.eq(10)).text()
85+
});
86+
});
87+
88+
return {"bowling_summary": bowlingSummary}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* -------------- STAGE 1 ------------ */
2+
3+
//------- 1.a Interaction Code ------ //
4+
5+
navigate('https://stats.espncricinfo.com/ci/engine/records/team/match_results.html?id=14450;type=tournament');
6+
7+
let data = parse();
8+
collect({
9+
'team_1': data.team1_data,
10+
'team_2': data.team2_data,
11+
'winner': data.winner_data,
12+
'margin': data.margin_data,
13+
'ground': data.ground_data,
14+
'match_date': data.match_date_data,
15+
'score_card': data.scorecard_data
16+
}
17+
);
18+
19+
20+
//------- 1.b Parser Code ------------//
21+
//Step1: defining all the json variable names (one json variable for one column)
22+
var team1Json = {};
23+
var team2Json = {};
24+
var winnerJson = {};
25+
var marginJson = {};
26+
var groundJson = {};
27+
var matchDateJson = {};
28+
var scorecardJson = {};
29+
30+
31+
//Step2: Selecting all rows we need from target table
32+
const allRows = $('table.engineTable > tbody > tr.data1');
33+
34+
35+
//Step3: Looping through each rows and get the data from the cells(td)
36+
allRows.each((index, element) => {
37+
const tds = $(element).find('td'); //find the td
38+
39+
//Pushing scraped data to respective json
40+
team1Json[index] = $(tds[0]).text();
41+
team2Json[index] = $(tds[1]).text();
42+
winnerJson[index] = $(tds[2]).text();
43+
marginJson[index] = $(tds[3]).text();
44+
groundJson[index] = $(tds[4]).text();
45+
matchDateJson[index] = $(tds[5]).text();
46+
scorecardJson[index] = $(tds[6]).text();
47+
})
48+
49+
// step4: Finally returning the data
50+
return {
51+
'team1_data': team1Json,
52+
'team2_data': team2Json,
53+
'winner_data': winnerJson,
54+
'margin_data': marginJson,
55+
'ground_data': groundJson,
56+
'match_date_data': matchDateJson,
57+
'scorecard_data': scorecardJson
58+
};
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/* -------------- STAGE 1 ------------ */
2+
3+
//------- 1.a Interaction Code ------ //
4+
5+
navigate('https://stats.espncricinfo.com/ci/engine/records/team/match_results.html?id=14450;type=tournament');
6+
7+
let links = parse().match_summary_links;
8+
for(let i of links) {
9+
next_stage({url: i})
10+
}
11+
12+
13+
//------- 1.b Parser Code ------------//
14+
let links = []
15+
const allRows = $('table.engineTable > tbody > tr.data1');
16+
allRows.each((index, element) => {
17+
const tds = $(element).find('td');
18+
const rowURL = "https://www.espncricinfo.com" +$(tds[6]).find('a').attr('href');
19+
links.push(rowURL);
20+
})
21+
return {
22+
'match_summary_links': links
23+
};
24+
25+
/* ------------ STAGE 2 -------------- */
26+
27+
//------- 2.a Interaction Code ------ //
28+
navigate(input.url);
29+
30+
31+
let players_data = parse().players_data;
32+
for(let obj of players_data) {
33+
name = obj['name']
34+
team = obj['team']
35+
url = obj['link']
36+
next_stage({name: name, team: team, url: url})
37+
}
38+
39+
//---------- 2.b Parser Code ---------//
40+
//to store all the players in a list
41+
var playersLinks = []
42+
43+
var match = $('div').filter(function(){
44+
return $(this)
45+
.find('span > span > span').text() === String("Match Details")
46+
}).siblings()
47+
team1 = $(match.eq(0)).find('span > span > span').text().replace(" Innings", "")
48+
team2 = $(match.eq(1)).find('span > span > span').text().replace(" Innings", "")
49+
50+
51+
//for batting players
52+
var tables = $('div > table.ci-scorecard-table');
53+
var firstInningRows = $(tables.eq(0)).find('tbody > tr').filter(function(index, element){
54+
return $(this).find("td").length >= 8
55+
})
56+
57+
var secondInningsRows = $(tables.eq(1)).find('tbody > tr').filter(function(index, element){
58+
return $(this).find("td").length >= 8
59+
});
60+
61+
firstInningRows.each((index, element) => {
62+
var tds = $(element).find('td');
63+
playersLinks.push({
64+
"name": $(tds.eq(0)).find('a > span > span').text().replace(' ', ''),
65+
"team": team1,
66+
"link": "https://www.espncricinfo.com" + $(tds.eq(0)).find('a').attr('href')
67+
});
68+
});
69+
70+
secondInningsRows.each((index, element) => {
71+
var tds = $(element).find('td');
72+
playersLinks.push({
73+
"name": $(tds.eq(0)).find('a > span > span').text().replace(' ', ''),
74+
"team": team2,
75+
"link": "https://www.espncricinfo.com" + $(tds.eq(0)).find('a').attr('href')
76+
});
77+
});
78+
79+
//for bowling players
80+
81+
var tables = $('div > table.ds-table');
82+
var firstInningRows = $(tables.eq(1)).find('tbody > tr').filter(function(index, element){
83+
return $(this).find("td").length >= 11
84+
})
85+
86+
var secondInningsRows = $(tables.eq(3)).find('tbody > tr').filter(function(index, element){
87+
return $(this).find("td").length >= 11
88+
});
89+
90+
91+
firstInningRows.each((index, element) => {
92+
var tds = $(element).find('td');
93+
playersLinks.push({
94+
"name": $(tds.eq(0)).find('a > span').text().replace(' ', ''),
95+
"team": team2.replace(" Innings", ""),
96+
"link": "https://www.espncricinfo.com" + $(tds.eq(0)).find('a').attr('href')
97+
98+
});
99+
});
100+
101+
secondInningsRows.each((index, element) => {
102+
var tds = $(element).find('td');
103+
playersLinks.push({
104+
"name": $(tds.eq(0)).find('a > span').text().replace(' ', ''),
105+
"team": team1.replace(" Innings", ""),
106+
"link": "https://www.espncricinfo.com" + $(tds.eq(0)).find('a').attr('href')
107+
});
108+
});
109+
110+
return {"players_data": playersLinks}
111+
112+
113+
/* ------------- STAGE 3 ------------ */
114+
115+
//------- 3.a Interaction Code ------ //
116+
117+
navigate(input.url);
118+
final_data = parse()
119+
collect(
120+
{
121+
"name": input.name,
122+
"team": input.team,
123+
"batting_style": final_data.bating_style,
124+
"bowling_style": final_data.bowling_style,
125+
"playing_role": final_data.playing_role,
126+
"description": final_data.content,
127+
});
128+
129+
//---------- 3.b Parser Code ---------//
130+
const batting_style = $('div.ds-grid > div').filter(function(index){
131+
return $(this).find('p').first().text() === String('batting_style')
132+
})
133+
134+
const bowling_style = $('div.ds-grid > div').filter(function(index){
135+
return $(this).find('p').first().text() === String('bowling_style')
136+
})
137+
138+
const playing_role = $('div.ds-grid > div').filter(function(index){
139+
return $(this).find('p').first().text() === String('playing_role')
140+
})
141+
142+
143+
return {
144+
"bating_style": batting_style.find('span').text(),
145+
"bowling_style": bowling_style.find('span').text(),
146+
"playing_role": playing_role.find('span').text(),
147+
"content": $('div.ci-player-bio-content').find('p').first().text()
148+
}

0 commit comments

Comments
 (0)