PHP code example of rem42 / scraper

1. Go to this page and download the library: Download rem42/scraper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rem42 / scraper example snippets


use Symfony\Component\HttpClient\HttpClient;
use Scraper\Scraper\Client;
use Scraper\Scraper\Request\ScraperRequest;
use Scraper\Scraper\Attribute\Scraper;
use Scraper\Scraper\Attribute\Method;
use Scraper\Scraper\Attribute\Scheme;
use Scraper\Scraper\Api\AbstractApi;

#[Scraper(
	method: Method::GET,
	scheme: Scheme::HTTPS,
	host: 'example.com',
	path: '/items/{id}'
)]
class ItemRequest extends ScraperRequest
{
	public function __construct(private string $id) {}
	public function getId(): string { return $this->id; }
}

// Provide a matching Api: ItemApi extends AbstractApi

$http = HttpClient::create();
$client = new Client($http);
$result = $client->send(new ItemRequest('42'));