Skip to content

Commit b694587

Browse files
committed
fixed constructor and driver standings functions which were not working
1 parent 3c9c0f4 commit b694587

File tree

4 files changed

+207
-13
lines changed

4 files changed

+207
-13
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`constrcutor standings 1`] = `
4+
[
5+
{
6+
"points": 78,
7+
"position": 1,
8+
"team": "McLaren Mercedes",
9+
},
10+
{
11+
"points": 57,
12+
"position": 2,
13+
"team": "Mercedes",
14+
},
15+
{
16+
"points": 36,
17+
"position": 3,
18+
"team": "Red Bull Racing Honda RBPT",
19+
},
20+
{
21+
"points": 17,
22+
"position": 4,
23+
"team": "Williams Mercedes",
24+
},
25+
{
26+
"points": 17,
27+
"position": 5,
28+
"team": "Ferrari",
29+
},
30+
{
31+
"points": 14,
32+
"position": 6,
33+
"team": "Haas Ferrari",
34+
},
35+
{
36+
"points": 10,
37+
"position": 7,
38+
"team": "Aston Martin Aramco Mercedes",
39+
},
40+
{
41+
"points": 6,
42+
"position": 8,
43+
"team": "Kick Sauber Ferrari",
44+
},
45+
{
46+
"points": 3,
47+
"position": 9,
48+
"team": "Racing Bulls Honda RBPT",
49+
},
50+
{
51+
"points": 0,
52+
"position": 10,
53+
"team": "Alpine Renault",
54+
},
55+
]
56+
`;
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`driver standings 1`] = `
4+
[
5+
{
6+
"driver": "Lando Norris",
7+
"nationality": "GBR",
8+
"points": 44,
9+
"position": 1,
10+
"team": "McLaren Mercedes",
11+
},
12+
{
13+
"driver": "Max Verstappen",
14+
"nationality": "NED",
15+
"points": 36,
16+
"position": 2,
17+
"team": "Red Bull Racing Honda RBPT",
18+
},
19+
{
20+
"driver": "George Russell",
21+
"nationality": "GBR",
22+
"points": 35,
23+
"position": 3,
24+
"team": "Mercedes",
25+
},
26+
{
27+
"driver": "Oscar Piastri",
28+
"nationality": "AUS",
29+
"points": 34,
30+
"position": 4,
31+
"team": "McLaren Mercedes",
32+
},
33+
{
34+
"driver": "Kimi Antonelli",
35+
"nationality": "ITA",
36+
"points": 22,
37+
"position": 5,
38+
"team": "Mercedes",
39+
},
40+
{
41+
"driver": "Alexander Albon",
42+
"nationality": "THA",
43+
"points": 16,
44+
"position": 6,
45+
"team": "Williams Mercedes",
46+
},
47+
{
48+
"driver": "Esteban Ocon",
49+
"nationality": "FRA",
50+
"points": 10,
51+
"position": 7,
52+
"team": "Haas Ferrari",
53+
},
54+
{
55+
"driver": "Lance Stroll",
56+
"nationality": "CAN",
57+
"points": 10,
58+
"position": 8,
59+
"team": "Aston Martin Aramco Mercedes",
60+
},
61+
{
62+
"driver": "Lewis Hamilton",
63+
"nationality": "GBR",
64+
"points": 9,
65+
"position": 9,
66+
"team": "Ferrari",
67+
},
68+
{
69+
"driver": "Charles Leclerc",
70+
"nationality": "MON",
71+
"points": 8,
72+
"position": 10,
73+
"team": "Ferrari",
74+
},
75+
{
76+
"driver": "Nico Hulkenberg",
77+
"nationality": "GER",
78+
"points": 6,
79+
"position": 11,
80+
"team": "Kick Sauber Ferrari",
81+
},
82+
{
83+
"driver": "Oliver Bearman",
84+
"nationality": "GBR",
85+
"points": 4,
86+
"position": 12,
87+
"team": "Haas Ferrari",
88+
},
89+
{
90+
"driver": "Yuki Tsunoda",
91+
"nationality": "JPN",
92+
"points": 3,
93+
"position": 13,
94+
"team": "Racing Bulls Honda RBPT",
95+
},
96+
{
97+
"driver": "Carlos Sainz",
98+
"nationality": "ESP",
99+
"points": 1,
100+
"position": 14,
101+
"team": "Williams Mercedes",
102+
},
103+
{
104+
"driver": "Isack Hadjar",
105+
"nationality": "FRA",
106+
"points": 0,
107+
"position": 15,
108+
"team": "Racing Bulls Honda RBPT",
109+
},
110+
{
111+
"driver": "Pierre Gasly",
112+
"nationality": "FRA",
113+
"points": 0,
114+
"position": 16,
115+
"team": "Alpine Renault",
116+
},
117+
{
118+
"driver": "Liam Lawson",
119+
"nationality": "NZL",
120+
"points": 0,
121+
"position": 17,
122+
"team": "Red Bull Racing Honda RBPT",
123+
},
124+
{
125+
"driver": "Jack Doohan",
126+
"nationality": "AUS",
127+
"points": 0,
128+
"position": 18,
129+
"team": "Alpine Renault",
130+
},
131+
{
132+
"driver": "Gabriel Bortoleto",
133+
"nationality": "BRA",
134+
"points": 0,
135+
"position": 19,
136+
"team": "Kick Sauber Ferrari",
137+
},
138+
]
139+
`;

src/scraper/constructors-standings.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ export const getConstructorStandings = async (year: number = new Date().getFullY
1111

1212
const response = await axios(`${dynamicLinks.rootLink}/${year}/${dynamicLinks.constructorStandings}`);
1313
const $ = cheerio.load(response.data);
14-
15-
$("tr").each(function () {
16-
const position: number = parseInt($(this).find("td:nth-child(2)").text().trim());
17-
const team: string = $(this).find("td:nth-child(3)").text().trim();
18-
const points: number = parseInt($(this).find("td:nth-child(4)").text().trim());
14+
$(".f1-table > tbody:nth-child(2) > tr").each(function () {
15+
const position: number = parseInt($(this).find("td:nth-child(1) > p:nth-child(1)").text().trim());
16+
const team: string = $(this).find("td:nth-child(2) > p:nth-child(1)").text().trim();
17+
const points: number = parseInt($(this).find("td:nth-child(3) > p:nth-child(1)").text().trim());
1918

2019
if (!Number.isNaN(position) && team.length !== 0 && !Number.isNaN(points)) {
2120
const constructorStanding: isConstructorStanding = {

src/scraper/driver-standings.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ export const getDriverStandings = async (year: number = new Date().getFullYear()
1212
const response = await axios(`${dynamicLinks.rootLink}/${year}/${dynamicLinks.driverStandings}`);
1313
const $ = cheerio.load(response.data);
1414

15-
$("tr").each(function () {
16-
const position: number = parseInt($(this).find(" td:nth-child(2) ").text());
17-
const firstName: string = $(this).find(" a.dark.bold.ArchiveLink > span:nth-child(1)").text();
18-
const lastName: string = $(this).find(" a.dark.bold.ArchiveLink > span:nth-child(2)").text();
19-
const driver = firstName.concat(" ", lastName);
20-
const nationality: string = $(this).find(" td.dark.semi-bold.uppercase").text();
21-
const team: string = $(this).find("td:nth-child(5) > a.grey.semi-bold.uppercase.ArchiveLink").text();
22-
const points: number = parseInt($(this).find(" td:nth-child(6) ").text());
15+
$(".f1-table > tbody:nth-child(2) > tr").each(function () {
16+
const position: number = parseInt($(this).find("td:nth-child(1) > p:nth-child(1)").text());
17+
const driver_1: string = $(this).find("td:nth-child(2) > p:nth-child(1) > a:nth-child(1) > span:nth-child(1)").text();
18+
const driver_2: string = $(this).find("td:nth-child(2) > p:nth-child(1) > a:nth-child(1) > span:nth-child(2)").text();
19+
const driver: string = driver_1.concat(" ", driver_2)
20+
const nationality: string = $(this).find(" td:nth-child(3) > p:nth-child(1)").text();
21+
const team: string = $(this).find("td:nth-child(4) > p:nth-child(1) > a:nth-child(1)").text();
22+
const points: number = parseInt($(this).find(" td:nth-child(5) > p:nth-child(1) ").text());
2323

2424
if (!Number.isNaN(position) && !Number.isNaN(points) && driver.length !== 0 && nationality.length !== 0 && team.length !== 0) {
2525
const driverStanding: isDriverStanding = {

0 commit comments

Comments
 (0)