本文整理汇总了PHP中Symfony\Component\DomCrawler\Crawler::extract方法的典型用法代码示例。如果您正苦于以下问题:PHP Crawler::extract方法的具体用法?PHP Crawler::extract怎么用?PHP Crawler::extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DomCrawler\Crawler
的用法示例。
在下文中一共展示了Crawler::extract方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extract
public function extract($attribute, $asString = false)
{
return true === $asString ? implode(null, parent::extract($attribute)) : parent::extract($attribute);
}
示例2: getSimilarSiblingsInfo
/**
* @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]];
}
示例3: getSource
/**
* @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;
}