public function extract($attribute, $asString = false) { return true === $asString ? implode(null, parent::extract($attribute)) : parent::extract($attribute); }
/** * @param Crawler $block * @return array */ public function getSimilarSiblingsInfo(Crawler $block) { $all_siblings = $block->parents()->first()->children(); $siblings = [$block]; $sample_node = $block->getNode(0); $sample_tag = $block->nodeName(); $sample_classes = explode(' ', $block->extract(['class'])[0]); foreach ($all_siblings as $sibling) { if ($sample_node->isSameNode($sibling)) { continue; } $to_add = false; if ($sibling->nodeName == $sample_tag) { if ($sample_classes === FALSE) { $to_add = true; } else { $sibling_classes = explode(' ', $sibling->getAttribute('class')); $matched_classes = array_intersect($sample_classes, $sibling_classes); if (!empty($matched_classes)) { if ($matched_classes != $sample_classes) { $sample_classes = $matched_classes; } $to_add = true; } } } if ($to_add) { $siblings[] = new Crawler($sibling); } } return [$siblings, ['tag' => $sample_tag, 'classes' => $sample_classes]]; }
/** * @param Crawler $image * @return string */ public function getSource(Crawler $image) { $source = $image->extract(['src'])[0]; if (strpos($source, $this->base_url) !== FALSE) { return $source; } $delimiter = ''; if ($source[0] != '/') { $delimiter = '/'; } return $this->base_url . $delimiter . $source; }