PHP code example of edulazaro / larascraper

1. Go to this page and download the library: Download edulazaro/larascraper 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/ */

    

edulazaro / larascraper example snippets


namespace App\Scrapers;

use EduLazaro\Larascraper\Scraper;

class BikeScraper extends Scraper
{
    protected function handle(): array
    {
        return [
            'title' => $this->crawler->filter('title')->text('')
        ];
    }
}

use App\Scrapers\BikeScraper;

$data = BikeScraper::scrape('https://whatever.com/bikes/4')
    ->proxy('ip:port', 'username', 'password') // Optional
    ->timeout(10000) // Optional timeout in ms
    ->headers(['Accept-Language' => 'en']) // Optional headers
    ->run();

dd($data);

namespace App\Scrapers;

use EduLazaro\Larascraper\Scraper;

class BikeScraper extends Scraper
{
    protected function handle(string $name): array
    {
        return [
            'title' => $this->crawler->filter($name)->text('')
        ];
    }
}

use App\Scrapers\BikeScraper;

BikeScraper::scrape('https://whatever.com/bikes/4')->run(name: 'title');

->proxy('200.20.14.84:40200')

->proxy('200.20.14.84:40200', 'username', 'password')

->timeout(10000) // Timeout in milliseconds

->headers([
    'Accept-Language' => 'en',
    'X-Custom-Header' => 'Hello'
])

->retry(3, 5)

$data = \App\Scrapers\TestScraper::scrape('https://whatever.com')->run();
dd($data);
bash
php artisan make:scraper BikeScraper
bash
php artisan make:scraper MyScraper
bash
php artisan list:scrapers
bash
php artisan tinker