protected function looksLikeGroupTitle(Crawler $node) { $tags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'strong', 'dt']; if (in_array($node->nodeName(), $tags)) { return true; } if (preg_match('/[#\\*\\-_=\\+]{2,}/', $node->text())) { return true; } if (':' === substr($node->text(), -1)) { return true; } if (false !== strpos($node->attr('class'), 'header')) { return true; } if (false !== strpos($node->attr('class'), 'title')) { return true; } return false; }
/** * Get the checked value from a radio group. * * @param \Symfony\Component\DomCrawler\Crawler $radioGroup * @return string|null * * @throws \Exception */ protected function getCheckedValueFromRadioGroup(Crawler $radioGroup) { if ($radioGroup->nodeName() !== 'input' || $radioGroup->attr('type') !== 'radio') { throw new Exception('Given element is not a radio button.'); } foreach ($radioGroup as $radio) { if ($radio->hasAttribute('checked')) { return $radio->getAttribute('value'); } } return; }
/** * Process general node. * * @since 0.9.0 * * @param \Symfony\Component\DomCrawler\Crawler $node * * @return \stdClass * * @author nguyenvanduocit */ public function process_General(Crawler &$node) { $newNode = new \stdClass(); $newNode->nodeName = $node->nodeName(); $newNode->text = $node->text(); return $newNode; }
/** * @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 $blocks * @return array */ public function lookupStructure(Crawler $blocks) { $structure = array(); foreach ($blocks as $block) { $block = new Crawler($block); $children = $block->children(); $children_structure = null; if ($children->getNode(0) != null) { $children_structure = $this->lookupStructure($children); } $structure[] = ['tag' => $block->nodeName(), 'children' => $children_structure]; } return $structure; }