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


PHP Crawler::addNode方法代码示例

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


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

示例1: getPositionData

 /**
  * @param Position $position
  * @param string $content
  */
 public function getPositionData(Position $position, $content)
 {
     $crawler = new Crawler($content);
     $trs = $crawler->filter('#full-props-list tr');
     $data = [];
     if ($trs->count() > 0) {
         foreach ($trs as $tr) {
             $crawler->clear();
             $crawler->addNode($tr);
             $th = $crawler->filter('th');
             $td = $crawler->filter('td');
             if ($th->count() > 0 && $td->count() > 0) {
                 $data[trim($th->text())] = trim($td->text());
             }
         }
     }
     $position->setAttributes($data);
 }
开发者ID:apoberez,项目名称:myLaboratory,代码行数:22,代码来源:HotlineProvider.php

示例2: testAddNode

 public function testAddNode()
 {
     $crawler = new Crawler();
     $crawler->addNode($this->createNodeList()->item(0));
     $this->assertEquals('foo', $crawler->filterXPath('//div')->attr('class'), '->addNode() adds nodes from a \\DOMNode');
 }
开发者ID:sapwoo,项目名称:portfolio,代码行数:6,代码来源:CrawlerTest.php

示例3: extractDump

 protected function extractDump($dump)
 {
     $crawler = new Crawler();
     $crawler->addContent($dump);
     foreach ($crawler->filter('table') as $table) {
         $table_crawler = new Crawler();
         $table_crawler->addNode($table);
         $tag_group_name = $table_crawler->attr('g1');
         $tag_full_name = $table_crawler->attr('name');
         $tag_g0 = $table_crawler->attr('g0');
         $tag_g2 = $table_crawler->attr('g2');
         $tags = $table_crawler->filter('tag');
         foreach ($tags as $tag) {
             $tag_crawler = new Crawler();
             $tag_crawler->addNode($tag);
             $extra = array();
             if ($tag_crawler->attr('g0')) {
                 $extra['local_g0'] = $tag_crawler->attr('g0');
             }
             if ($tag_crawler->attr('g1') && !in_array($tag_crawler->attr('g1'), array('MakerNotes', 'Chapter#'))) {
                 $g_name = $tag_crawler->attr('g1');
                 $extra['local_g1'] = $tag_crawler->attr('g1');
             } else {
                 $g_name = $tag_group_name;
             }
             if ($tag_crawler->attr('g2')) {
                 $extra['local_g2'] = $tag_crawler->attr('g2');
             }
             $flags = explode(',', $tag_crawler->attr('flags'));
             if (in_array('Avoid', $flags)) {
                 $extra['flag_Avoid'] = 'true';
             }
             if (in_array('Binary', $flags)) {
                 $extra['flag_Binary'] = 'true';
             }
             if (in_array('Permanent', $flags)) {
                 $extra['flag_Permanent'] = 'true';
             }
             if (in_array('Protected', $flags)) {
                 $extra['flag_Protected'] = 'true';
             }
             if (in_array('Unsafe', $flags)) {
                 $extra['flag_Unsafe'] = 'true';
             }
             if (in_array('List', $flags)) {
                 $extra['flag_List'] = 'true';
             }
             if (in_array('Mandatory', $flags)) {
                 $extra['flag_Mandatory'] = 'true';
             }
             if (in_array('Bag', $flags)) {
                 $extra['flag_Bag'] = 'true';
             }
             if (in_array('Seq', $flags)) {
                 $extra['flag_Seq'] = 'true';
             }
             if (in_array('Alt', $flags)) {
                 $extra['flag_Alt'] = 'true';
             }
             $subspace = str_replace('::', '\\', $g_name);
             $tag_name = $tag_crawler->attr('name');
             $classname = self::generateClassname($tag_name);
             $tag_id = $tag_crawler->attr('id');
             $properties = array_merge(array('Id' => $tag_id, 'Name' => $tag_name, 'FullName' => $tag_full_name, 'GroupName' => $g_name, 'g0' => $tag_g0, 'g1' => $tag_group_name, 'g2' => $tag_g2, 'Type' => $tag_crawler->attr('type'), 'Writable' => $tag_crawler->attr('writable'), 'Description' => $tag_crawler->filter('desc[lang="en"]')->first()->text()), $extra);
             if ($tag_crawler->attr('count')) {
                 $properties['MaxLength'] = $tag_crawler->attr('count');
             }
             $this->types[$tag_crawler->attr('type')] = $tag_crawler->attr('type');
             if ($tag_crawler->attr('index')) {
                 $properties['Index'] = $tag_crawler->attr('index');
             }
             if (count($tag_crawler->filter('values')) > 0) {
                 $values = array();
                 $values_tag = $tag_crawler->filter('values')->first();
                 $Keys = $values_tag->filter('key');
                 foreach ($Keys as $Key) {
                     $KeyCrawler = new Crawler();
                     $KeyCrawler->addNode($Key);
                     $Id = $KeyCrawler->attr('id');
                     $Label = $KeyCrawler->filter('val[lang="en"]')->first()->text();
                     $values[$Id] = array('Id' => $Id, 'Label' => $Label);
                 }
                 $properties['Values'] = $values;
             }
             $this->createTagClass($subspace, $classname, $properties);
         }
     }
     $this->generateTypes();
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:89,代码来源:ClassesBuilder.php

示例4: testAddNode

 /**
  * @covers Symfony\Component\DomCrawler\Crawler::addNode
  */
 public function testAddNode()
 {
     if (!class_exists('Symfony\\Component\\CssSelector\\CssSelector')) {
         $this->markTestSkipped('The "CssSelector" component is not available');
     }
     $crawler = new Crawler();
     $crawler->addNode($this->createNodeList()->item(0));
     $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addNode() adds nodes from an \\DOMNode');
 }
开发者ID:rouffj,项目名称:symfony,代码行数:12,代码来源:CrawlerTest.php


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