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


PHP Crawler::attr方法代码示例

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


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

示例1: process

 public function process()
 {
     $crawler = $this->client->request($this->plan['method'], $this->plan['uri']);
     if (isset($this->plan['selector'])) {
         $selection = $crawler->filter($this->plan['selector']);
     } elseif (isset($this->plan['xpath'])) {
         $selection = $crawler->filterXPath($this->plan['path']);
     }
     if ($this->plan['images']) {
         $images = $selection->filterXPath('//img');
         if (iterator_count($images) > 1) {
             foreach ($images as $image) {
                 $crawler = new Crawler($image);
                 $info = parse_url($this->plan['uri']);
                 $url = $info['scheme'] . '://' . $info['host'] . '/' . $crawler->attr('src');
                 if (strpos($crawler->attr('src'), 'http') === 0) {
                     $url = $info['scheme'] . '://' . $info['host'] . '/' . $this->plan['path'] . $crawler->attr('src');
                 }
                 copy($url, SCRYPHP_STORAGE_PATH_IMG . DIRECTORY_SEPARATOR . substr(strrchr($url, "/"), 1));
             }
         }
     }
     file_put_contents(SCRYPHP_STORAGE_PATH_TXT . DIRECTORY_SEPARATOR . time() . uniqid(time(), true) . '.txt', $selection->text());
     return $selection->text();
 }
开发者ID:siad007,项目名称:scryphp,代码行数:25,代码来源:Plan.php

示例2: hasAttributes

 /**
  * Determines if the given element has the attributes.
  *
  * @param \Symfony\Component\DomCrawler\Crawler $element
  *
  * @return bool
  */
 protected function hasAttributes(Crawler $element)
 {
     foreach ($this->attributes as $name => $value) {
         if (is_numeric($name)) {
             if (is_null($element->attr($value))) {
                 return false;
             }
         } else {
             if ($element->attr($name) != $value) {
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:notadd,项目名称:framework,代码行数:22,代码来源:HasElement.php

示例3: parse

 public function parse(Crawler $node, $rules, array &$return = [])
 {
     if (is_string($rules)) {
         return ':attr' === $rules ? $node->attr($rules) : $node->filter($rules)->count() ? $node->filter($rules)->text() : null;
     } elseif (is_callable($rules)) {
         return $rules($node);
     }
     foreach ($rules as $key => &$rule) {
         switch ($key) {
             case 0 === strpos($key, '@'):
                 $this->property($node, $key, $rule, $return);
                 break;
             case ':first':
                 return $this->parse($node->first(), $rule, $return);
             case ':next-sibling':
                 return $this->parse($node->siblings()->first(), $rule, $return);
             case ':parent':
                 return $this->parse($node->parents()->first(), $rule, $return);
             case ':each':
                 return $this->each($node, $rule);
             case ':attr':
                 return $node->attr($rule);
             default:
                 return $this->parse($node->filter($key), $rule, $return);
         }
     }
     return $return;
 }
开发者ID:v3kwip,项目名称:tudien,代码行数:28,代码来源:Parser.php

示例4: looksLikeGroupTitle

 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;
 }
开发者ID:ssnepenthe,项目名称:recipe-scraper,代码行数:20,代码来源:Base.php

示例5: addFeed

 /**
  * @param Crawler $node
  * @param $url
  * @return string
  */
 protected static function addFeed(Crawler $node, $url)
 {
     if (!$node->attr('href')) {
         return;
     }
     $uri = FeedLink::factory($node, $url)->getUri();
     if (!static::isValidUrl($uri) || in_array($uri, static::$feeds) || static::$strict && !static::isValidFeed($uri)) {
         return;
     }
     static::$feeds[] = $uri;
 }
开发者ID:norikt,项目名称:feedseek,代码行数:16,代码来源:Feedseek.php

示例6: getProductsLinks

 private function getProductsLinks(string $url) : array
 {
     $links = [];
     $html = file_get_contents($url);
     $crawler = new Crawler($html);
     $productsLinks = $crawler->filter('.ttle .g_statistic');
     foreach ($productsLinks as $node) {
         $linkNode = new Crawler($node);
         $links[] = $linkNode->attr('href');
     }
     return $links;
 }
开发者ID:petryshend,项目名称:shop,代码行数:12,代码来源:ProductCrawler.php

示例7: getCidades

 /**
  * Metodo para capturar as cidades da uf
  *
  * @param  $codUf
  * @throws Exception
  * @return array
  */
 public static function getCidades($codUf = null)
 {
     $cidades = array();
     $client = new Client();
     $crawler = $client->request('GET', 'http://www.cidades.ibge.gov.br/xtras/uf.php?lang=&coduf=' . $codUf);
     $lis = $crawler->filter('#lista_municipios > li');
     foreach ($lis as $li) {
         $li = new Crawler($li);
         $codigo = substr($li->attr('id'), 1);
         $cidades[] = ['codigo' => $codigo, 'nome' => $li->filter('a')->html()];
     }
     return $cidades;
 }
开发者ID:danielnogueira84,项目名称:cidades-gratis,代码行数:20,代码来源:Cidades.php

示例8: processBid

 /**
  * Transform a bid HTML node into a bid array
  * @param  Crawler $node HTML bid node
  * @return array        bid
  */
 protected function processBid(Crawler $node)
 {
     $bid = array();
     $bid['title'] = $node->attr('title');
     $bid['price'] = $node->filter('.price')->count() ? trim($node->filter('.price')->text()) : null;
     $bid['url'] = $node->attr('href');
     preg_match('@/\\w+/(?P<id>\\d+)\\.htm\\?ca=\\d+_s@', $bid['url'], $matches);
     $bid['bid_id'] = $matches['id'];
     $category = trim($node->filter('.category')->text());
     $bid['is_pro'] = strstr($category, '(pro)') ? true : false;
     list($date, $time) = $node->filter('.date > div')->each(function ($node, $i) {
         return $node->text();
     });
     $bid['created_at'] = new LeboncoinDatetime($date, $time);
     $bid['picture'] = $node->filter('.image')->children()->count() ? $node->filter('.image-and-nb > img')->attr('src') : null;
     $placement = trim($node->filter('.placement')->text());
     $placement = explode('/', $placement);
     $placement = array_map(function ($item) {
         return trim($item);
     }, $placement);
     $bid['placement'] = implode(' / ', $placement);
     return $bid;
 }
开发者ID:inscriptionweb,项目名称:leboncoin-cli,代码行数:28,代码来源:Client.php

示例9: createPackages

 public function createPackages()
 {
     DB::table('stores')->truncate();
     $response = $this->crawlerLink('https://play.google.com/store/apps?hl=en&gl=us');
     $crawler = new Crawler($response);
     $links = $crawler->filter('body a.child-submenu-link');
     $data = [];
     foreach ($links as $i => $link) {
         $temp = new Crawler($link);
         $data[$i] = 'https://play.google.com' . $temp->attr('href') . '/collection/topselling_free?hl=en&gl=us';
     }
     foreach ($data as $item) {
         $packages = $this->googlePackageListFromPage($item);
         foreach ($packages as $package) {
             DB::table('stores')->insert([
                 'name' => $package,
                 'status' => 'not'
             ]);
         }
     }
 }
开发者ID:hungnt88,项目名称:5stars-1,代码行数:21,代码来源:GoogleCrawler.php

示例10: __construct

 public function __construct(Crawler $node)
 {
     $this->node = $node;
     $this->url = $node->attr('href');
 }
开发者ID:rfussien,项目名称:leboncoin-crawler,代码行数:5,代码来源:SearchResultAdCrawler.php

示例11: post

 /**
  *
  * @param \Bpi\Sdk\Document $document
  */
 public function post(Document $document)
 {
     $document->request('POST', $this->crawler->attr('href'), $this->render());
 }
开发者ID:rimi-itk,项目名称:bpi-client,代码行数:8,代码来源:Template.php

示例12: dontSeeNodeAttribute

 /**
  * @param \Symfony\Component\DomCrawler\Crawler $node
  * @param array $name
  */
 public function dontSeeNodeAttribute($node, $name)
 {
     $this->assertEquals('', $node->attr($name));
 }
开发者ID:mfavetti,项目名称:LimeSurvey,代码行数:8,代码来源:CodeHelper.php

示例13: getKivee

 public function getKivee()
 {
     set_time_limit(10000);
     $base_url = 'http://www.kiveeshop.com/';
     $client = new Client();
     $products = [];
     $template_replaced = '{{page}}';
     $template_urls = [$base_url . '4-tops', $base_url . '14-outwears', $base_url . '15-dresses', $base_url . '13-bottoms'];
     foreach ($template_urls as $key => $template_url) {
         for ($i = 1; $i <= 5; $i++) {
             $url = str_replace($template_replaced, $i, $template_url);
             $header_url = get_headers($url, 1);
             if ($header_url[0] == 'HTTP/1.0 404 Not Found') {
                 break;
             }
             $crawler = $client->request('GET', $url);
             $products_crawler = $crawler->filter('.ajax_block_product a');
             foreach ($products_crawler as $key => $product_crawler) {
                 $node = new Crawler($product_crawler);
                 $url_page_link = $node->attr('href');
                 $page_crawler = $client->request('GET', $url_page_link);
                 $name = $page_crawler->filter('#ContentPlaceHolderBody_ContentPlaceHolderBreadCrumb_lblNamaProduk')->text();
                 $price = $page_crawler->filter('#lblHargaAwal')->text();
                 $sale_price = $page_crawler->filter('#lblHarga')->text();
                 $desc = $page_crawler->filter('#cssmenu ul li div')->text();
                 $images = [];
                 $images_obj = $page_crawler->filter('.slider-relative img');
                 foreach ($images_obj as $image_obj) {
                     $images[] = $image_obj->getAttribute('src');
                 }
                 // header(s'Content-Type: application/json');
                 $product = new Product();
                 $product->title = $name;
                 $product->price = filter_var($price, FILTER_SANITIZE_NUMBER_INT);
                 $product->description = preg_replace('/\\s+/', ' ', $desc);
                 $product->sale_price = filter_var($sale_price, FILTER_SANITIZE_NUMBER_INT);
                 $product->url = $url_page_link;
                 $product->save();
                 foreach ($images as $key => $image) {
                     $photo = new ProductPhoto();
                     $photo->photo_url = str_replace('./', $base_url, $image);
                     $photo->thumbnail_url = str_replace('./', $base_url, $image);
                     $photo->product_id = $product->id;
                     $photo->save();
                 }
                 $products[] = ['name' => $name, 'price' => $price, 'images' => $images];
             }
             $next_page = $crawler->filter('.pagination_next.disabled');
             if (sizeof($next_page) < 1) {
                 break;
             }
         }
     }
 }
开发者ID:limahfud,项目名称:skripsi,代码行数:54,代码来源:ScrappingController.php

示例14: __construct

 /**
  * @param Crawler $node
  * @param string $currentUri
  */
 public function __construct(Crawler $node, $currentUri)
 {
     parent::__construct($node->getNode(0), $currentUri);
     $this->type = strtolower(trim($node->attr('type')));
 }
开发者ID:norikt,项目名称:feedseek,代码行数:9,代码来源:FeedLink.php

示例15: getReturn

 /**
  * Get return information (type, description) from a DOMNode
  *
  * @param \DOMNode $node The DOMNode to parse
  *
  * @return array First element is the type, second the description
  */
 protected function getReturn(\DOMNode $node)
 {
     $crawler = new Crawler($node);
     $type = $crawler->attr('type');
     $description = $this->getInner($node);
     return array($type, $description);
 }
开发者ID:alexandresalome,项目名称:php-selenium,代码行数:14,代码来源:XmlLoader.php


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