當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Crawler::count方法代碼示例

本文整理匯總了PHP中Symfony\Component\DomCrawler\Crawler::count方法的典型用法代碼示例。如果您正苦於以下問題:PHP Crawler::count方法的具體用法?PHP Crawler::count怎麽用?PHP Crawler::count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\DomCrawler\Crawler的用法示例。


在下文中一共展示了Crawler::count方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: parse

 public function parse($url)
 {
     $chunks = parse_url($url);
     if ($chunks['path'] !== Urls::URL_ALBUM) {
         $this->logger->error('Unknown URL received');
         return;
     }
     $host = $chunks['host'];
     $schema = $chunks['scheme'];
     $this->logger->info('Resolved host and schema', ['host' => $host, 'schema' => $schema]);
     $this->logger->info('Fetching url', ['url' => $url]);
     $response = $this->guzzle->get($url);
     $this->logger->info('Fetched first page', ['url' => $url]);
     $crawler = new Crawler((string) $response->getBody());
     $links = $crawler->filter(Selectors::SELECTOR_PAGINATION_NUMBER_LINKS);
     $pages = [];
     for ($i = 0; $i < $crawler->count(); $i++) {
         $link = $links->eq($i);
         $chunks = parse_url($link->attr('href'));
         parse_str($chunks['query'], $query);
         $pages[] = $query['page'];
     }
     $this->logger->info('', ['pages' => $pages]);
 }
開發者ID:entership,項目名稱:srany-parser,代碼行數:24,代碼來源:ParserLauncher.php

示例2: getFieldValue

 /**
  * Return the field's value
  *
  * @param $node
  * @param $defaultValue
  * @param $callback
  * @param string $funcName
  * @param string $funcParam
  *
  * @return mixed
  */
 private function getFieldValue(Crawler $node, $defaultValue, $callback, $funcName = 'text', $funcParam = '')
 {
     if ($node->count()) {
         return $callback($node->{$funcName}($funcParam));
     }
     return $defaultValue;
 }
開發者ID:rfussien,項目名稱:leboncoin-crawler,代碼行數:18,代碼來源:SearchResultAdCrawler.php

示例3: getPaginationInfo

 private function getPaginationInfo(Crawler $info)
 {
     $result = new \stdClass();
     switch ($info->count()) {
         case 0:
             // no results
             $result->total_results = 0;
             $result->results_per_page = 10;
             // (last item - first) + 1 => Items 21 -> 40 => 40-21+1 = 20 items.
             $result->num_pages = 0;
             $result->first_on_page = 0;
             $result->last_on_page = 0;
             $result->current_page = 0;
             break;
         case 1:
             $aux = explode(PHP_EOL, $info->text());
             $info = array_pop($aux);
             $info = explode(' ', $info);
             $result->total_results = intval($info[4]);
             $result->results_per_page = intval($info[2]) - intval($info[0]) + 1;
             // (last item - first) + 1 => Items 21 -> 40 => 40-21+1 = 20 items.
             $result->num_pages = intval(ceil($result->total_results / $result->results_per_page));
             $result->first_on_page = intval($info[0]);
             $result->last_on_page = intval($info[2]);
             $result->current_page = intval(ceil($result->first_on_page / $result->results_per_page));
             break;
     }
     return $result;
 }
開發者ID:vgomes,項目名稱:daftapi,代碼行數:29,代碼來源:DaftOverseas.php

示例4: count

 /**
  * Length of items in document
  *
  * @group Iterator
  */
 public function count()
 {
     return $this->crawler->count();
 }
開發者ID:aakb,項目名稱:bpi-client,代碼行數:9,代碼來源:Document.php


注:本文中的Symfony\Component\DomCrawler\Crawler::count方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。