Falcon 🌎
Drivers πŸ”Ž

Drivers πŸ”Ž

Custom Drivers

Start by creating your own driver class that extends the DriverInterface interface and implement the driver specific logic within that class.

$falcon = Falcon::getInstance();
 
$falcon->addDrivers([
  "MyCustomDriver" => MyCustomDriver::class
]);

Every driver should implement their own scraping logic and has to have the following method(s):

scrape(string $target, array $options)

The $target is the site that will get scraped and $options are passed from Falcon which hold all miscellaneous data such as headers & cookies. Applying these options is up to the driver itself.

The scrape method in a custom driver should return the dom of the website which is then processed by the default hQuery driver and parsed by Falcon. This enables us to keep the parsing logic as tiny as possible and not needing to implement custom parsing logic within the custom driver itself. This also means that the parsing logic will never change and all your custom parsers will still work despite having a custom driver.

The diagram below shows what happens when you add a custom driver to Falcon.

...to be added...

Broilerplate driver

<?php 
 
use Antheta\Falcon\Drivers\Interfaces\DriverInterface;
 
class MyCustomDriver implements DriverInterface
{
    public function scrape(string $target, $options = []) {
        // implement scraping logic here
        // return dom
    }
}