Skip to content

Commit 3da16a5

Browse files
committed
fixed hall of fame and fastest lap functions
1 parent 6a4d57a commit 3da16a5

File tree

6 files changed

+168
-24
lines changed

6 files changed

+168
-24
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
The scraper scrapes this website: <https://www.formula1.com>
66

7+
**Completely Updated According to the F1 New Website Changes ~ 2025!**
8+
79
## Installation
810

911
```bash
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`fastest laps 1`] = `
4+
[
5+
{
6+
"car": "McLaren MercedesMcLaren Mercedes",
7+
"driver": "LandoLando NorrisNorris",
8+
"grandPrix": "AustraliaChina",
9+
"time": "1:22.1671:35.454",
10+
},
11+
]
12+
`;
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`hall of fame 1`] = `
4+
[
5+
{
6+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-856948472",
7+
"name": "Nino Farina",
8+
},
9+
{
10+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9North/fom-website/manual/Hall of Fame 2024/GettyImages-827612408",
11+
"name": "Juan Manuel Fangio",
12+
},
13+
{
14+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9South/fom-website/manual/Hall of Fame 2024/GettyImages-106501211",
15+
"name": "Alberto Ascari",
16+
},
17+
{
18+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9North/fom-website/manual/Hall of Fame 2024/GettyImages-1068321752",
19+
"name": "Mike Hawthorn",
20+
},
21+
{
22+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9North/fom-website/manual/Hall of Fame 2024/GettyImages-3323162",
23+
"name": "Jack Brabham",
24+
},
25+
{
26+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9North/fom-website/manual/Hall of Fame 2024/GettyImages-71183243",
27+
"name": "Phil Hill",
28+
},
29+
{
30+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-864209082",
31+
"name": "Graham Hill",
32+
},
33+
{
34+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-1328924500",
35+
"name": "Jim Clark",
36+
},
37+
{
38+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-3072443",
39+
"name": "John Surtees",
40+
},
41+
{
42+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9South/fom-website/manual/Hall of Fame 2024/GettyImages-1063718326",
43+
"name": "Denny Hulme",
44+
},
45+
{
46+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9South/fom-website/manual/Hall of Fame 2024/GettyImages-1443308803",
47+
"name": "Jackie Stewart",
48+
},
49+
{
50+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9South/fom-website/manual/Hall of Fame 2024/GettyImages-831631668",
51+
"name": "Jochen Rindt",
52+
},
53+
{
54+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9South/fom-website/manual/Hall of Fame 2024/GettyImages-1189103543",
55+
"name": "Emerson Fittipaldi",
56+
},
57+
{
58+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-525577811",
59+
"name": "Niki Lauda",
60+
},
61+
{
62+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9South/fom-website/manual/Hall of Fame 2024/GettyImages-827647160",
63+
"name": "James Hunt",
64+
},
65+
{
66+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-851859388",
67+
"name": "Mario Andretti",
68+
},
69+
{
70+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-79750356",
71+
"name": "Jody Scheckter",
72+
},
73+
{
74+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9South/fom-website/manual/Hall of Fame 2024/GettyImages-868507192",
75+
"name": "Alan Jones",
76+
},
77+
{
78+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-1066217104",
79+
"name": "Nelson Piquet",
80+
},
81+
{
82+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9South/fom-website/manual/Hall of Fame 2024/GettyImages-464497739",
83+
"name": "Keke Rosberg",
84+
},
85+
{
86+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-537112453",
87+
"name": "Alain Prost",
88+
},
89+
{
90+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-659224375",
91+
"name": "Ayrton Senna",
92+
},
93+
{
94+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-865701928",
95+
"name": "Nigel Mansell",
96+
},
97+
{
98+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-72220757",
99+
"name": "Michael Schumacher",
100+
},
101+
{
102+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-868558648",
103+
"name": "Damon Hill",
104+
},
105+
{
106+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-52918273",
107+
"name": "Jacques Villeneuve",
108+
},
109+
{
110+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9South/fom-website/manual/Hall of Fame 2024/GettyImages-647968497",
111+
"name": "Mika Hakkinen",
112+
},
113+
{
114+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-55768339",
115+
"name": "Fernando Alonso",
116+
},
117+
{
118+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9South/fom-website/manual/Hall of Fame 2024/GettyImages-2071874459",
119+
"name": "Kimi Raikkonen",
120+
},
121+
{
122+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-1285771774",
123+
"name": "Lewis Hamilton",
124+
},
125+
{
126+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-91979303",
127+
"name": "Jenson Button",
128+
},
129+
{
130+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9Centre/fom-website/manual/Hall of Fame 2024/GettyImages-82801122",
131+
"name": "Sebastian Vettel",
132+
},
133+
{
134+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320,t_16by9North/fom-website/manual/Hall of Fame 2024/GettyImages-607523452",
135+
"name": "Nico Rosberg",
136+
},
137+
{
138+
"driver_image": "https://media.formula1.com/image/upload/f_auto,c_limit,q_auto,w_1320/content/dam/fom-website/sutton/2021/AbuDhabi/Sunday/1358623736",
139+
"name": "Max Verstappen",
140+
},
141+
]
142+
`;

src/scraper/fastest-laps.ts

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

15-
$("tr").each(function () {
16-
const grandPrix: string = $(this).find("td.width30.dark").text().trim();
17-
const driverFirstName: string = $(this).find("td.width25.dark.bold > span.hide-for-mobile").text().trim();
18-
const driverLastName: string = $(this).find("td.width25.dark.bold > span.hide-for-tablet").text().trim();
19-
const car: string = $(this).find("td.width25.semi-bold.uppercase").text().trim();
20-
const time: string = $(this).find("td:nth-child(5)").text().trim();
15+
$(".f1-table > tbody:nth-child(2)").each(function () {
16+
const grandPrix: string = $(this).find("td:nth-child(1) > p:nth-child(1)").text().trim();
17+
const driverFirstName: string = $(this).find("td:nth-child(2) > p:nth-child(1) > span:nth-child(1)").text().trim();
18+
const driverLastName: string = $(this).find("td:nth-child(2) > p:nth-child(1) > span:nth-child(2)").text().trim();
19+
const car: string = $(this).find("td:nth-child(3) > p:nth-child(1)").text().trim();
20+
const time: string = $(this).find("td:nth-child(4) > p:nth-child(1)").text().trim();
2121

2222
const driver: string = driverFirstName.concat(" ", driverLastName);
2323

src/scraper/world-champions.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,15 @@ export const getWorldChampions = async (): Promise<isHallOfFame[]> => {
1212
const response = await axios(staticLinks.hallOfFame);
1313
const $ = cheerio.load(response.data);
1414

15-
$("article").each(function () {
16-
const years: number[] = [];
15+
$("div.grid:nth-child(2) > a").each(function () {
1716

18-
const name: string = $(this).find("section > h4").text().trim().split("-")[0];
19-
$(this)
20-
.find("section > h4")
21-
.text()
22-
.trim()
23-
.split("-")[1]
24-
.split(",")
25-
.forEach((x) => {
26-
if (x) {
27-
const year: number = parseInt(x);
28-
years.push(year);
29-
}
30-
});
17+
const name: string = $(this).find("figure:nth-child(1) > figcaption:nth-child(2) > p:nth-child(1)").text().trim();
18+
const driver_image: string | undefined = $(this).find("figure:nth-child(1) > picture:nth-child(1) > img:nth-child(1)").attr("src")
3119

32-
if (name.length !== 0 && years.length !== 0) {
20+
if (name.length !== 0 && driver_image?.length !== 0) {
3321
const worldChampion: isHallOfFame = {
3422
name,
35-
years,
23+
driver_image,
3624
};
3725
worldChampions.push(worldChampion);
3826
}

src/types/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export type isTeam = {
3030

3131
export type isHallOfFame = {
3232
name: string;
33-
years: number[];
33+
driver_image: string | undefined;
3434
};
3535

3636
export type isRaceResult = {

0 commit comments

Comments
 (0)