Symfony\Component\DomCrawler\Crawler::addNode PHP 메소드

addNode() 공개 메소드

Adds a \DOMNode instance to the list of nodes.
public addNode ( DOMNode $node )
$node DOMNode A \DOMNode instance
    public function addNode(\DOMNode $node)
    {
        if ($node instanceof \DOMDocument) {
            $node = $node->documentElement;
        }
        if (null !== $this->document && $this->document !== $node->ownerDocument) {
            throw new \InvalidArgumentException('Attaching DOM nodes from multiple documents in the same crawler is forbidden.');
        }
        if (null === $this->document) {
            $this->document = $node->ownerDocument;
        }
        // Don't add duplicate nodes in the Crawler
        if (in_array($node, $this->nodes, true)) {
            return;
        }
        $this->nodes[] = $node;
    }

Usage Example

예제 #1
0
 /**
  * @param Position $position
  * @param string $content
  */
 public function getPositionData(Position $position, $content)
 {
     $crawler = new Crawler($content);
     $trs = $crawler->filter('#full-props-list tr');
     $data = [];
     if ($trs->count() > 0) {
         foreach ($trs as $tr) {
             $crawler->clear();
             $crawler->addNode($tr);
             $th = $crawler->filter('th');
             $td = $crawler->filter('td');
             if ($th->count() > 0 && $td->count() > 0) {
                 $data[trim($th->text())] = trim($td->text());
             }
         }
     }
     $position->setAttributes($data);
 }
All Usage Examples Of Symfony\Component\DomCrawler\Crawler::addNode