當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。