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


PHP Crawler::children方法代码示例

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


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

示例1: getSelectedValueFromSelect

 /**
  * Get the selected value from a select field.
  *
  * @param  \Symfony\Component\DomCrawler\Crawler  $select
  * @return array
  */
 protected function getSelectedValueFromSelect(Crawler $select)
 {
     $selected = [];
     foreach ($select->children() as $option) {
         if ($option->nodeName === 'optgroup') {
             foreach ($option->childNodes as $child) {
                 if ($child->hasAttribute('selected')) {
                     $selected[] = $this->getOptionValue($child);
                 }
             }
         } elseif ($option->hasAttribute('selected')) {
             $selected[] = $this->getOptionValue($option);
         }
     }
     return $selected;
 }
开发者ID:timpressive,项目名称:art-auction,代码行数:22,代码来源:IsSelected.php

示例2: parse

 public static function parse($contents)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent($contents, 'UTF-8');
     $items = $crawler->filter('td[style="padding-left: 5px;"] table[width="100%"]');
     //Bypass Undefined variable error.
     $staff = null;
     $characters = null;
     foreach ($items as $item) {
         //Bypass to determine if the last table contains the staff members
         $crawler = new Crawler($item);
         if ($crawler->filter('td[width="27"]')->count() != 1) {
             $staffitems = $crawler->children();
             foreach ($staffitems as $staffitem) {
                 $staff[] = self::parseStaff($staffitem);
             }
         } else {
             $characters[] = self::parseCharacters($crawler);
         }
     }
     return array('Characters' => $characters, 'Staff' => $staff);
 }
开发者ID:AnimeNeko,项目名称:atarashii-mal-api,代码行数:22,代码来源:CastParser.php

示例3: getSelectedValueFromSelect

 /**
  * Get the selected value from a select field.
  *
  * @param  \Symfony\Component\DomCrawler\Crawler  $field
  * @return string|null
  *
  * @throws \Exception
  */
 protected function getSelectedValueFromSelect(Crawler $field)
 {
     if ($field->nodeName() !== 'select') {
         throw new Exception('Given element is not a select element.');
     }
     foreach ($field->children() as $option) {
         if ($option->hasAttribute('selected')) {
             return $option->getAttribute('value');
         }
     }
     return;
 }
开发者ID:hanifn,项目名称:laravel-framework,代码行数:20,代码来源:InteractsWithPages.php

示例4: authorGroup

 function authorGroup(Crawler $groupNode)
 {
     $data = ['link' => '', 'pages' => []];
     $done = false;
     $groupNode->children()->each(function (Crawler $node) use(&$data, &$done) {
         if ($done) {
             return;
         }
         switch (strtolower($node->nodeName())) {
             case 'p':
                 $links = $node->filter('b a');
                 $name = firstNode($links, function (Crawler $node) {
                     return trim($node->attr('name')) != '';
                 });
                 $title = firstNode($links, function (Crawler $node) {
                     return trim($node->text()) != '';
                 });
                 $link = firstNode($links, function (Crawler $node) {
                     return trim($node->attr('href')) != '';
                 });
                 $data['idx'] = intval(str_replace('gr', '', $name->attr('name')));
                 $data['title'] = trim($title->text(), ' :');
                 $data['link'] = $link ? $link->attr('href') : null;
                 $about = $node->filter('font i')->first();
                 $data['annotation'] = trim($about->html());
                 break;
             case 'dl':
                 $data['pages'][] = $this->groupPage($node);
                 break;
             case 'h3':
                 $done = true;
         }
     });
     return $data;
 }
开发者ID:ankhzet,项目名称:Ankh,代码行数:35,代码来源:Parser.php

示例5: seeNodeNumChildren

 /**
  * @param \Symfony\Component\DomCrawler\Crawler $node
  * @param integer $amount
  */
 public function seeNodeNumChildren($node, $amount, $filter = null)
 {
     $count = $filter !== null ? $node->filter($filter)->count() : $node->children()->count();
     $this->assertEquals($amount, $count);
 }
开发者ID:mfavetti,项目名称:LimeSurvey,代码行数:9,代码来源:CodeHelper.php

示例6: indexGames

 public function indexGames()
 {
     $crawler = new Crawler();
     //--------------------extract all product details----------------------
     global $products;
     $products = array();
     $html = file_get_contents("http://www.lelong.com.my/toys-and-games/game-console/");
     $crawler->addContent($html);
     //------------------extract retailer logo------------------------
     //$retailer_logo = $crawler->filter('div#top1Logo img')->attr('src');
     //---------------------------------------------------------------
     //---------------------------filter category-------------------------------
     $category = $crawler->filter('a[href="/toys-and-games/game-console/"]')->text();
     //-------------------------------------------------------------------------
     $crawler->filter('div.item4inline')->each(function ($crawler) {
         for ($i = 2; $i <= 5;) {
             $url = 'http://www.lelong.com.my/toys-and-games/game-console/?D=' . $i;
             $html = file_get_contents($url);
             $crawler->addContent($html);
             global $products;
             global $rank;
             $rank = $crawler->filter('span.catalogTitle')->each(function ($crawler, $i) use(&$products) {
                 $products[$i]['title'] = $crawler->text();
                 $products[$i]['url'] = str_replace('//', '', $crawler->parents()->attr('href'));
             });
             $rank = $crawler->filter('div.catalogPrice b')->each(function ($crawler, $i) use(&$products) {
                 $toReplace = array('RM', ',');
                 $with = array('', '');
                 $products[$i]['price'] = str_replace($toReplace, $with, $crawler->text());
             });
             $rank = $crawler->filter('div.catalog-wrap')->each(function ($crawler, $i) use(&$products) {
                 $products[$i]['image'] = $crawler->parents()->attr('id');
             });
             $rank = $crawler->filter('div.catalogIcon')->each(function ($crawler, $i) use(&$products) {
                 $products[$i]['shipping'] = $crawler->children()->text();
             });
             ++$rank;
             $i++;
             //print_r($products);
         }
     });
     //--------------insert data using model-----------------
     foreach ($products as $pro) {
         $product = new Products();
         if ($category == 'Game Console') {
             $product->category_id = 6;
             $product->condition_id = 3;
         }
         $arrProduct = explode(' ', $pro['title']);
         $brands = \DB::table('brand')->whereIn('brand_title', $arrProduct)->get();
         if ($brands) {
             foreach ($brands as $brand) {
                 $product->brand_id = $brand->id;
             }
         } else {
             $product->brand_id = 204;
         }
         $product->product_name = $pro['title'];
         $product->shopper_link = $pro['url'];
         $product->product_price = $pro['price'];
         $product->picture_link = $pro['image'];
         $product->product_shipping = $pro['shipping'];
         $product->save();
     }
     //-------------------------------------------------------
 }
开发者ID:aminaminamin93,项目名称:pricescales,代码行数:66,代码来源:crawlLelongController.php

示例7: getSelectedValueFromSelect

 /**
  * Get the selected value from a select field.
  *
  * @param  \Symfony\Component\DomCrawler\Crawler  $field
  * @return array
  *
  * @throws \Exception
  */
 protected function getSelectedValueFromSelect(Crawler $field)
 {
     if ($field->nodeName() !== 'select') {
         throw new Exception('Given element is not a select element.');
     }
     $selected = [];
     foreach ($field->children() as $option) {
         if ($option->nodeName === 'optgroup') {
             foreach ($option->childNodes as $child) {
                 if ($child->hasAttribute('selected')) {
                     $selected[] = $child->getAttribute('value');
                 }
             }
         } elseif ($option->hasAttribute('selected')) {
             $selected[] = $option->getAttribute('value');
         }
     }
     return $selected;
 }
开发者ID:joseluisordonez,项目名称:dis,代码行数:27,代码来源:InteractsWithPages.php

示例8: lookupStructure

 /**
  * @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;
 }
开发者ID:nfqakademija,项目名称:dydis-turi-reiksme,代码行数:18,代码来源:Validationer.php

示例9: getPrice

 /**
  * Get the price value from a pricePerUnit node
  *
  * @param Crawler $node
  * @return string
  */
 protected function getPrice(Crawler $node)
 {
     $children = '';
     foreach ($node->children() as $child) {
         $children .= $child->nodeValue;
     }
     $text = $node->text();
     $price = mb_substr($text, 0, mb_strpos($text, $children));
     // remove /unit
     $price = trim($price, "£ \t\n\r\v");
     // remove whitespace and pound @TODO handle different currencies
     return $price;
 }
开发者ID:peterhough,项目名称:sainsburys,代码行数:19,代码来源:Scraper.php

示例10: indexGames

 public function indexGames()
 {
     $crawler = new Crawler();
     //-------------extract all product details------------------
     global $products;
     $products = array();
     $html = file_get_contents("http://www.mudah.my/Malaysia/Games-and-Consoles-for-sale-3120?lst=0&fs=1&cg=3120&w=3&so=1&st=s");
     $crawler->addContent($html);
     //------------------filter category------------------------
     $category = $crawler->filter('a[title="See all ads in Games & Consoles category"] span')->text();
     //----------------------------------------------------------
     $crawler->filter('div.listing_thumbs')->each(function ($crawler) {
         for ($i = 2; $i <= 5;) {
             $url = 'http://www.mudah.my/Malaysia/Games-and-Consoles-for-sale-3120?o=' . $i . '&q=&so=1&th=1';
             $html = file_get_contents($url);
             $crawler->addContent($html);
             global $rank;
             global $products;
             $rank = $crawler->filter('h2.list_title.truncate a')->each(function ($crawler, $i) use(&$products) {
                 $products[$i]['title'] = $crawler->text();
                 $products[$i]['url'] = $crawler->attr('href');
             });
             $rank = $crawler->filter('div.ads_price')->each(function ($crawler, $i) use(&$products) {
                 $toReplace = array(' ', 'RM');
                 $with = array('', '');
                 $products[$i]['price'] = str_replace($toReplace, $with, $crawler->text());
             });
             $rank = $crawler->filter('li.listing_thumbs_image img')->each(function ($crawler, $i) use(&$products) {
                 $products[$i]['image'] = $crawler->attr('src');
             });
             $rank = $crawler->filter('div.location')->each(function ($crawler, $i) use(&$products) {
                 $products[$i]['location'] = str_replace(' ', '', $crawler->children()->siblings()->text());
             });
             $rank = $crawler->filter('div[title="Condition"]')->each(function ($crawler, $i) use(&$products) {
                 $products[$i]['condition'] = $crawler->text();
             });
             ++$rank;
             $i++;
             //print_r($products);
         }
     });
     //--------------insert data using model-----------------
     foreach ($products as $pro) {
         $product = new Products();
         if ($category == 'Games & Consoles') {
             $product->category_id = 6;
         }
         $arrProduct = explode(' ', $pro['title']);
         $brands = \DB::table('brand')->whereIn('brand_title', $arrProduct)->get();
         if ($brands) {
             foreach ($brands as $brand) {
                 $product->brand_id = $brand->id;
             }
         } else {
             $product->brand_id = 1;
         }
         $product->product_name = $pro['title'];
         $product->shopper_link = $pro['url'];
         $product->product_price = $pro['price'];
         $product->picture_link = str_replace('thumbs', 'images', $pro['image']);
         $product->product_location = $pro['location'];
         if ($pro['condition'] == 'New') {
             $product->condition_id = 1;
         } else {
             $product->condition_id = 2;
         }
         $product->save();
     }
     //--------------------------------------------------------
     return "<div class='alert alert-success'>Successfully crawler site</div>";
 }
开发者ID:aminaminamin93,项目名称:pricescales,代码行数:71,代码来源:crawlMudahController.php


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