class EventsScraper (View source)

The EventsScraper class is responsible for scraping a list of events from a given URL and returning an array of EventDTOs.

It uses an HTTP client to fetch the HTML content and a parser to extract the relevant information.

Example usage: $httpClient = new DefaultHttpClient(); $parser = new ParseEvents(); $scraper = new EventsScraper($httpClient, $parser); $events = $scraper->scrape('https://www.blackcombat.com/events'); // $events will contain an array of EventDTOs with the scraped event details

Constants

private URL

Methods

__construct(HttpClientInterface $http, ParseEvents $parser)

EventsScraper constructor.

array
scrape(string|null $url = null)

Scrape a list of events from the given URL and return an array of EventDTOs.

Details

__construct(HttpClientInterface $http, ParseEvents $parser)

EventsScraper constructor.

Parameters

HttpClientInterface $http

An HTTP client for fetching HTML content.

ParseEvents $parser

A parser for extracting event details from HTML.

array scrape(string|null $url = null)

Scrape a list of events from the given URL and return an array of EventDTOs.

If no URL is provided, it defaults to the predefined URL for events. The method fetches the HTML content from the URL and uses the parser to extract event details, returning them as an array of EventDTOs.

Note: The actual structure of EventDTOs and the parsing logic will depend on the implementation of the ParseEvents parser. Make sure to handle any exceptions or errors that may occur during the HTTP request or parsing process as needed.

Example usage: $events = $scraper->scrape(); // Scrapes from the default URL $events = $scraper->scrape('https://www.blackcombat.com/custom-events'); // Scrapes from a custom URL

Parameters

string|null $url

The URL of the events page to scrape. If null, the default URL will be used.

Return Value

array

An array of EventDTOs with the scraped event details.