ufcscraper.event_scraper module

This module contains the EventScraper class, which is responsible for scraping event data from the UFCStats website.

The EventScraper class inherits from BaseScraper and provides functionality to retrieve and process event details such as event name, date, city, state, and country. The scraped data is stored in a CSV file (event_data.csv) and can be used for further analysis.

class ufcscraper.event_scraper.EventScraper(data_folder: Path | str, n_sessions: int | None = None, delay: float | None = None)[source]

Bases: BaseScraper

Scrapes event data from the UFCStats website.

This class handles scraping event details such as event name, date, city, state, and country, and stores them in a CSV file. It inherits basic scraping functionality from BaseScraper.

data = Empty DataFrame Columns: [event_id, event_name, event_date, event_city, event_state, event_country] Index: []
dtypes: Dict[str, type | pd.core.arrays.integer.Int64Dtype] = {'event_city': <class 'str'>, 'event_country': <class 'str'>, 'event_date': 'datetime64[ns]', 'event_id': <class 'str'>, 'event_name': <class 'str'>, 'event_state': <class 'str'>}
event_type = 'completed'
filename: str = 'event_data.csv'
get_event_urls() List[str][source]

Retrieves the URLs of all completed events from UFCStats.

This method scrapes the UFCStats website for event URLs that contain the keyword ‘event-details’. It returns a list of these URLs.

Returns:

A list of URLs for completed events.

get_fight_urls_from_event_urls(event_urls: List[str]) List[str][source]

Extracts fight URLs from a list of event URLs.

Parameters:

event_urls – A list of event URLs from which to extract fight URLs.

Returns:

A list of fight URLs extracted from the provided event URLs.

scrape_events() None[source]

Scrapes event data and saves it to a CSV file.

This method compares existing event URLs with those available on the UFCStats website, scrapes details of new events, and appends them to the CSV file. Logs the progress and any errors encountered.

sort_fields: List[str] = ['event_date', 'event_name']
classmethod url_from_id(id_: str) str[source]

Constructs the event URL using the event ID.

Parameters:

id – The unique identifier for the event.

Returns:

The full URL to the event’s details page on UFCStats.

class ufcscraper.event_scraper.UpcomingEventScraper(data_folder: Path | str, n_sessions: int | None = None, delay: float | None = None)[source]

Bases: EventScraper

event_type = 'upcoming'
filename: str = 'upcoming_event_data.csv'
get_fight_urls_from_event_urls(event_urls: List[str]) List[str][source]

Extracts fight URLs from a list of event URLs.

Parameters:

event_urls – A list of event URLs from which to extract fight URLs.

Returns:

A list of fight URLs extracted from the provided event URLs.