EventsScraper
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
Scrape a list of events from the given URL and return an array of EventDTOs.
Details
__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.
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