2017 © Pedro Peláez
 

library dom-crawler

Symfony DomCrawler *fork for supplying your own DOMDocument / DOMElement classes.

image

dan/dom-crawler

Symfony DomCrawler *fork for supplying your own DOMDocument / DOMElement classes.

  • Sunday, November 22, 2015
  • by dan
  • Repository
  • 1 Watchers
  • 0 Stars
  • 16 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 85 Forks
  • 0 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

DomCrawler Component *fork

DomCrawler eases DOM navigation for HTML and XML documents., (*1)

Symfony's DomCrawler 2.7.6 modified so you may swap in your own DOMDocument and DOMElement descendant classes. If you have no need to do such a thing, then you should be using the regular but awesome Symfony DomCrawler., (*2)

The composer.json file has been modified to include Symfony's CssSelector Component because they're like peas and carrots :), (*3)

Install

$ composer require "dan/dom-crawler" "dev-master"

How should I apply this fork?

Here is an example of how to extend DOMDocument and DOMElement and effectively use this fork., (*4)

Firstly, here is our awesome DOMElement:, (*5)

<?php

namespace My\Awesome;

class ExtDOMDocument extends \DOMDocument
{
    public function __construct($version, $encoding)
    {
        parent::__construct($version, $encoding);
        parent::registerNodeClass('DOMElement', '\\My\\Awesome\\ExtDOMElement');
    }

    public function setRoot($name) 
    {
        return $this->appendChild(new ExtDOMElement($name));
    }
}

With its associative DOMElement:, (*6)

<?php

namespace My\Awesome;

class ExtDOMElement extends \DOMElement
{
    public function appendElement($name) 
    {
        return $this->appendChild(new ExtDOMElement($name));
    }
}

Then you can use Crawler with your new extended classes:, (*7)

use Dan\Symfony\Component\DomCrawler\Crawler;

$crawler = new Crawler();
$crawler->registerDOMDocumentClass('My\\Awesome\\ExtDOMDocument');
$crawler->addContent('<html><body>

Hello World!, (*8)

</body></html>'); $filter = $crawler->filterXPath('descendant-or-self::body/p')->first(); print get_class($filter->getNode(0)); // My\Awesome\ExtDOMElement

If you are also using the CssSelector component, you can use CSS Selectors instead of XPath expressions:, (*9)

use Dan\Symfony\Component\DomCrawler\Crawler;

$crawler = new Crawler();
$crawler->registerDOMDocumentClass('My\\Awesome\\ExtDOMDocument');
$crawler->addContent('<html><body>

Hello World!, (*10)

</body></html>'); print $crawler->filter('body > p')->text(); $filter = $crawler->filterXPath('descendant-or-self::body/p')->first(); print get_class($filter->getNode(0)); // My\Awesome\ExtDOMElement

Unit Tests

You can run the unit tests with the following command:, (*11)

$ cd path/to/Dan/Symfony/Component/DomCrawler/
$ composer install
$ phpunit

The Versions

22/11 2015

dev-master

9999999-dev https://danrichards.net/

Symfony DomCrawler *fork for supplying your own DOMDocument / DOMElement classes.

  Sources   Download

MIT

The Requires

 

22/11 2015

v2.7.99

2.7.99.0 https://danrichards.net/

Symfony DomCrawler *fork for supplying your own DOMDocument / DOMElement classes.

  Sources   Download

MIT

The Requires

 

21/11 2015

2.7.x-dev

2.7.9999999.9999999-dev https://danrichards.net/

Symfony DomCrawler Fork for AiCrawler

  Sources   Download

MIT

The Requires

 

02/11 2015

2.8.x-dev

2.8.9999999.9999999-dev https://symfony.com

Symfony DomCrawler Component

  Sources   Download

MIT

The Requires

 

The Development Requires

02/11 2015

2.3.x-dev

2.3.9999999.9999999-dev https://symfony.com

Symfony DomCrawler Component

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

09/07 2015

2.6.x-dev

2.6.9999999.9999999-dev https://symfony.com

Symfony DomCrawler Component

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

03/01 2015

2.5.x-dev

2.5.9999999.9999999-dev http://symfony.com

Symfony DomCrawler Component

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

22/09 2014

2.4.x-dev

2.4.9999999.9999999-dev http://symfony.com

Symfony DomCrawler Component

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

29/11 2013

2.2.x-dev

2.2.9999999.9999999-dev http://symfony.com

Symfony DomCrawler Component

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

16/05 2013

2.1.x-dev

2.1.9999999.9999999-dev http://symfony.com

Symfony DomCrawler Component

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

19/02 2013

2.0.x-dev

2.0.9999999.9999999-dev http://symfony.com

Symfony DomCrawler Component

  Sources   Download

MIT

The Requires

  • php >=5.3.2