PHP code example of mitseo / scraper

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

    

mitseo / scraper example snippets


use Mitseo\Scraper\Scraper;

$string = "11111 222 33333 44444";

$regex1 = Scraper::regex("/[0-9]{5}/")->match($string);
$regex2 = Scraper::regex("/([0-9]{5})/")->extractFirst($string);
$regex3 = Scraper::regex("/([0-9]{5})/")->extractAll($string);
$regex4 = Scraper::regex("/[0-9]{5}/")->count($string);


use Mitseo\Scraper\Scraper;

$dom = file_get_contents('https://en.wikipedia.com/');

$xpath1 = Scraper::xpath("//a")->match($dom);
$xpath2 = Scraper::xpath("//a")->extractFirst($dom);
$xpath3 = Scraper::xpath("//a")->extractAll($dom);
$xpath3 = Scraper::xpath("//a")->count($dom);
$xpath4 = Scraper::xpath("//a",["anchor"=>".","href"=>"@href"])->extractTree($dom);

use Mitseo\Scraper\Scraper;

$dom = file_get_contents('https://en.wikipedia.com/');

$css1 = Scraper::css("h1#truc")->match($dom);
$css2 = Scraper::css("h1")->extractFirst($dom);
$css3 = Scraper::css("a")->extractAll($dom);
$css4 = Scraper::css("a")->count($dom);