UFC Scraper
![](https://upload.wikimedia.org/wikipedia/commons/d/d7/UFC_Logo.png)
https://www.npmjs.com/package/ufc-scraper
Overview
The ufc-scraper
package provides a set of functions to scrape UFC fighter information, statistics, and rankings from the UFC website. It uses axios
for making HTTP requests and cheerio
for parsing HTML content. This package enables you to programmatically retrieve detailed UFC fighter data, including fighter information, statistics, records, and official rankings.
Installation
To install the package, use npm:
npm install ufc-scraper
Usage
Below are the primary functions provided by the ufc-scraper
package and how to use them.
getFighter
Retrieves both fighter information and statistics.
import { getFighter } from 'ufc-scraper';
getFighter('max holloway').then(fighter => {
if (fighter) {
console.log(fighter);
} else {
console.log('Failed to retrieve fighter data.');
}
});
getFighterInfo
Retrieves basic information about a fighter.
import { getFighterInfo } from 'ufc-scraper';
getFighterInfo('max holloway').then(info => {
if (info) {
console.log(info);
} else {
console.log('Failed to retrieve fighter information.');
}
});
getFighterStats
Retrieves statistics about a fighter.
import { getFighterStats } from 'ufc-scraper';
getFighterStats('max holloway').then(stats => {
if (stats) {
console.log(stats);
} else {
console.log('Failed to retrieve fighter statistics.');
}
});
getRankings
Retrieves UFC rankings.
import { getRankings } from 'ufc-scraper';
getRankings().then(rankings => {
if (rankings) {
console.log(rankings);
} else {
console.log('Failed to retrieve rankings.');
}
});
getTitleholders
Retrieves the current UFC titleholders, categorized by division.
import { getTitleholders } from 'ufc-scraper';
getTitleholders().then(titleholders => {
if (titleholders) {
console.log(titleholders);
} else {
console.log('Failed to retrieve titleholders.');
}
});
getRecords
Retrieves UFC career records and statistics across various categories.
import { getRecords } from 'ufc-scraper';
getRecords().then(records => {
if (records) {
console.log(records);
} else {
console.log('Failed to retrieve records.');
}
});
Functions
getFighter(fighterName: string): Promise<Fighter | null>
Retrieves both fighter information and statistics for the given fighter name.
getFighterInfo(fighterName: string): Promise<FighterInfo | null>
Retrieves basic information about the fighter, including name, nickname, status, age, height, weight, reach, fighting style, division, place of birth, training camp, octagon debut, and image URL.
getFighterStats(fighterName: string): Promise<FighterStats | null>
Retrieves detailed statistics about the fighter, including their record, win methods, average fight time, significant strikes by position and target, striking accuracy, and takedown accuracy.
getRankings(): Promise<Rankings | null>
Retrieves the current UFC rankings, categorized by weight class.
getTitleholders(): Promise<Titleholders | null>
Retrieves the current UFC titleholders, categorized by division.
getRecords(): Promise<Records | null>
Retrieves UFC career records and statistics across various categories.
Interfaces
Fighter
interface Fighter {
FighterInfo: FighterInfo | null;
FighterStats: FighterStats | null;
}
FighterInfo
interface FighterInfo {
Name: string;
Nickname: string;
Status: string;
Age: string;
Height: string;
Weight: string;
ArmReach: string;
LegReach: string;
FightingStyle: string;
Division: string;
PlaceOfBirth: string;
TrainingCamp: string;
OctagonDebut: string;
ImageURL: string | undefined;
}
FighterStats
interface FighterStats {
Record: string;
WinByMethod: {
KO: string;
Decision: string;
Submission: string;
};
AvgFightTime: string;
SigStrikeByPosition: {
Standing: string;
Clinch: string;
Ground: string;
};
SigStrikeByTarget: {
Head: string;
Body: string;
Leg: string;
};
StrikingAccuracy: {
SigStrikesLanded: string;
SigStrikesAttempted: string;
};
TakedownAccuracy: {
TakedownsLanded: string;
TakedownsAttempted: string;
};
}
Rankings
interface Rankings {
[Division: string]: {
[rank: number]: string;
};
}
Titleholders
interface Titleholders {
[Division: string]: {
Weight: string;
ChampName: string;
ChampNickname: string;
ChampRecord: string;
ChampLastFight: string;
};
}
'Records'
interface Records {
[Category: string]: {
[Rank: number]: {
Fighter: string;
Statistic: string;
}
};
}
Error Handling
Each function logs errors to the console and returns null
in case of any issues encountered during the scraping process. Make sure to handle null
values appropriately in your application to avoid unexpected crashes.
Example
Here is a complete example of using the ufc-scraper
package to retrieve and display information about a specific UFC fighter:
import { getFighter, getRankings, getTitleholders, getRecords } from 'ufc-scraper';
getFighter('max holloway').then((fighter) => {
console.log(fighter);
});
getRankings().then((rankings) => {
console.log(rankings);
});
getTitleholders().then((titleholders) => {
console.log(titleholders);
});
getRecords().then((records) => {
console.log(records);
});
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or bug fixes.