PHP code example of mehrabx / web-crawler

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

    

mehrabx / web-crawler example snippets



//set list of URLs and selects DOM elements of each URL page
$urls = [
    'https://test.exp/?page=1' => ["//img[@class='type1']","//a[@class='type1']"],
    'https://test.exp/?page=2' => ["//img[@class='type2'"],
    'https://test.exp/?page=3' => "//img[@class='type3']",
];

//return array of results
return \Crawler\Facades\CrawlFacade::make($urls)->start() ;



$urls = [
    'https://test.exp/?page=1' => ["//img[@class='type1']","//a[@class='type1']"],
    'https://test.exp/?page=2' => ["//img[@class='type2'"],
];

//set 5 seconds sleep time 
return \Crawler\Facades\CrawlFacade::make($urls)->sleep(10)->start() ;


$urls = [
    'https://test.exp/?page=1', //this url has not select
    'https://test.exp/?page=2' => ["//img[@class='type2'"],
];

return \Crawler\Facades\CrawlFacade::make($urls)
                                    ->defaultSelect("//img[@class='type1']")
                                    ->start() ;