PHP code example of mkocztorz / data-scraper

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

    

mkocztorz / data-scraper example snippets


use Mkocztorz\DataScraper\Std\Extractor;
$extractor = new Extractor();

 $data = $extractor->extract($crawler); //step 2 - the actual scraping
 

$extractor->getText('#title');

$extractor->getTextPattern('#title', ['pattern'=>'/UID-(?P<value>\d+)/']);

$extractor->getAttribute('#title', ['attr'=>'age']);

$extractor->getAttributePattern('#title', ['attr'=>'id', 'pattern'=>'/user-(?P<value>\d+)/']);

$extractor->getList('ul li', [
    'name' => $extractor->getText('h1'),    // actually selecting: "ul li h1"
    'age'  => $extractor->getText('p'),     // actually selecting: "ul li p"
    'id'   => $extractor->getAttribute('', ['attr'=>'id']), // actually selecting "ul li", assuming that each li will have id attribute
]);