Skip to content
A simple php Web Scraper that wrap up Guzzle and DomCrawler
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
LICENSE
README.md
composer.json
phpunit.xml.dist

README.md

g-crawler

A simple php Web Scraper that wrap up Guzzle and DomCrawler

Installation

Add package dependency to your project

composer require uatthaphon/g-crawler

Usage

In your PHP project

Once GCrawler is included in your project you may add it to any class by simply init.

use GCrawler\GCrawler;


class Example {
    protected $_gCrawler;
    
    public function __construct()
    {
            $this->_gCrawler = new GCrawler($config);
    }
    
    public function run()
    {
            $crawler = $_gCrawler->crawler('https://www.example.com/');
            $text = $crawler->filter('div.here')
                ->each(function ($node) {
                        return $node->text();
                };
                
            return $text;
    }
    

Or init with config

use GCrawler\GCrawler;


class Example {
    protected $_gCrawler;
    
    public function __construct()
    {
            $config = [
                'headers' => [
                    'User-Agent' => 'testing/1.0',
                    'Accept' => 'application/json',
                    'X-Foo' => ['Bar', 'Baz'],
                ]
            ];
            $this->_gCrawler = new GCrawler($config);
    }
    
    public function run()
    {
            $crawler = $_gCrawler->crawler('https://www.example.com/');
            $text = $crawler->filter('div.here')
                ->each(function ($node) {
                        return $node->text();
                };
                
            return $text;
    }
    

License

g-crawler is released under the MIT License.

You can’t perform that action at this time.