当前位置: 首页>>代码示例>>PHP>>正文


PHP Crawler::each方法代码示例

本文整理汇总了PHP中Symfony\Component\DomCrawler\Crawler::each方法的典型用法代码示例。如果您正苦于以下问题:PHP Crawler::each方法的具体用法?PHP Crawler::each怎么用?PHP Crawler::each使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\DomCrawler\Crawler的用法示例。


在下文中一共展示了Crawler::each方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: format

 public function format(Crawler $crawler, array $config)
 {
     $locations = $config['locations'];
     $return = $crawler->each(function (Crawler $node, $i) use($locations) {
         // Symfony dom-crawler methods ignore text nodes, so we have to
         // revert to native DOMNode methods instead.
         $children = $node->getNode(0)->childNodes;
         $values = [];
         foreach ($children as $child) {
             // Skip non element or text nodes.
             if (!in_array($child->nodeType, [1, 3])) {
                 continue;
             }
             // Loop through locations but stop after the first truthy value.
             foreach ($locations as $location) {
                 if ('_text' === $location && ($value = trim($child->nodeValue))) {
                     $values[] = $value;
                     continue 2;
                 }
                 // DOMText does not have method hasAttribute.
                 if (1 === $child->nodeType && $child->hasAttribute($location) && ($value = trim($child->getAttribute($location)))) {
                     $values[] = $value;
                     continue 2;
                 }
             }
         }
         // Remove any lingering 'empty' elements.
         $value = implode(' ', array_filter(array_map('trim', $values)));
         if ($this->looksLikeGroupTitle($node)) {
             $value = '%%TITLE%%' . $value . '%%TITLE%%';
         }
         return $value;
     });
     return [array_shift($return)];
 }
开发者ID:ssnepenthe,项目名称:recipe-scraper,代码行数:35,代码来源:SingleFromChildren.php

示例2: __construct

 /**
  * @param Crawler $nodes
  */
 public function __construct(Crawler $nodes)
 {
     $this->nodes = [];
     $nodes->each(function ($node) {
         $this->nodes[] = $node;
     });
 }
开发者ID:bramdevries,项目名称:changelog,代码行数:10,代码来源:AbstractRetriever.php

示例3: getXml

 protected function getXml(Crawler $crawler)
 {
     $document = new \DOMDocument('1.0', 'utf-8');
     $crawler->each(function (\DOMElement $node) use($document) {
         $document->appendChild($document->importNode($node, true));
     });
     return html_entity_decode($document->saveXML());
 }
开发者ID:nicolasbui,项目名称:BeSimpleSsoAuthBundle,代码行数:8,代码来源:WebTestCase.php

示例4: format

 public function format(Crawler $crawler, array $config)
 {
     $locations = $config['locations'];
     $return = $crawler->each(function (Crawler $node, $i) use($locations) {
         $values = $node->extract($locations);
         /**
          * Remove falsey values and normalize result...
          *
          * If 1 == count($locations), $values will contain strings,
          * otherwise $values will contain arrays.
          */
         if (is_array($values[0])) {
             $values = array_filter($values[0]);
         }
         if ($this->looksLikeGroupTitle($node)) {
             $values = array_map(function ($value) {
                 return '%%TITLE%%' . $value . '%%TITLE%%';
             }, $values);
         }
         return array_shift($values);
     });
     return array_values(array_filter($return));
 }
开发者ID:ssnepenthe,项目名称:recipe-scraper,代码行数:23,代码来源:Multi.php

示例5: setCardFromMD

 /**
  * create card from microdata && save it in cardContainer
  * 
  * @param Crawler $scope
  * @param string $url
  */
 private function setCardFromMD(Crawler $scope, $url)
 {
     $scope->each(function (Crawler $node) use($url) {
         try {
             $type = $this->parser->getCardType($node);
             $card = $this->createCard($type);
         } catch (\RuntimeException $e) {
             $card = $this->createCard('Thing');
         }
         if ($node->attr('itemprop')) {
             $this->childArray[] = $card;
         }
         $card->child = count($node->filter('[itemscope]')) - 1;
         $card->url = $url;
         $this->parser->setCardProperties($node, $card);
         $this->saveCard($card);
     });
 }
开发者ID:uthmordar,项目名称:cardator,代码行数:24,代码来源:Cardator.php

示例6: getCasts

 private function getCasts(Crawler $links)
 {
     $staffs = [];
     $links->each(function (Crawler $link, $i) use(&$staffs) {
         if (!preg_match('/id=(\\d+)/', $link->attr('href'), $matches)) {
             return;
         }
         $staff = new Staffs();
         list($name, $aka) = CrawlDmmTask::parseNameAndAka(trim($link->text()));
         $staff->name = $name;
         $staff->aka = $aka ? implode(',', $aka) : null;
         $staff->id = $matches[1];
         $staffs[] = $staff;
     });
     return $staffs;
 }
开发者ID:AlloVince,项目名称:yinxing,代码行数:16,代码来源:ImportDmmTask.php


注:本文中的Symfony\Component\DomCrawler\Crawler::each方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。