/** * Returns DOMElement from crawler instance. * * @param Crawler $crawler * * @return \DOMElement * * @throws DriverException when the node does not exist */ private function getCrawlerNode(Crawler $crawler) { $node = null; if ($crawler instanceof \Iterator) { // for symfony 2.3 compatibility as getNode is not public before symfony 2.4 $crawler->rewind(); $node = $crawler->current(); } else { $node = $crawler->getNode(0); } if (null !== $node) { return $node; } throw new DriverException('The element does not exist'); }
/** * Iterates over all properties of current item */ public function walkProperties($callback) { $crawler = new Crawler($this->crawler->current()); return $crawler->filter('item property')->each(function ($e) use($callback) { $sxml = simplexml_import_dom($e); $callback(current($sxml->attributes()) + array('@value' => (string) $sxml)); }); }
/** * @param $content string * * @return string */ private function removeLastItem($content) { $document = new \DOMDocument('1.0', \Yii::$app->charset); $crawler = new Crawler(); $crawler->addHTMLContent($content, \Yii::$app->charset); $root = $document->appendChild($document->createElement('_root')); $crawler->rewind(); $root->appendChild($document->importNode($crawler->current(), true)); $domxpath = new \DOMXPath($document); $crawlerInverse = $domxpath->query(CssSelector::toXPath($this->widgetItem . ':last-child')); foreach ($crawlerInverse as $key => $elementToRemove) { $parent = $elementToRemove->parentNode; $parent->removeChild($elementToRemove); } $crawler->clear(); $crawler->add($document); return $crawler->filter('body')->eq(0)->html(); }
/** * Returns DOMElement from crawler instance. * * @param Crawler $crawler * * @return \DOMElement * * @throws DriverException when the node does not exist */ private function getCrawlerNode(Crawler $crawler) { $crawler->rewind(); $node = $crawler->current(); if (null !== $node) { return $node; } throw new DriverException('The element does not exist'); }
/** * (PHP 5 >= 5.0.0)<br/> * Return the current element * @link http://php.net/manual/en/iterator.current.php * @return mixed Can return any type. */ public function current() { $node = $this->crawler->current(); $data = $this->extractor->extract($node); return $data; }