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


PHP Crawler::addDocument方法代碼示例

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


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

示例1: assertSelectEquals

 /**
  * assertSelectEquals("#binder .name", "Chuck", true,  $xml);  // any?
  * assertSelectEquals("#binder .name", "Chuck", false, $xml);  // none?
  *
  * @param array                 $selector
  * @param string                $content
  * @param integer|boolean|array $count
  * @param mixed                 $actual
  * @param string                $message
  * @param boolean               $isHtml
  * @since Method available since Release 1.0.0
  *
  * @throws PHPUnit_Framework_Exception
  */
 public static function assertSelectEquals($selector, $content, $count, $actual, $message = '', $isHtml = true)
 {
     $crawler = new Crawler();
     if ($actual instanceof DOMDocument) {
         $crawler->addDocument($actual);
     } else {
         if ($isHtml) {
             $crawler->addHtmlContent($actual);
         } else {
             $crawler->addXmlContent($actual);
         }
     }
     $crawler = $crawler->filter($selector);
     if (is_string($content)) {
         $crawler = $crawler->reduce(function (Crawler $node, $i) use($content) {
             if ($content === '') {
                 return $node->text() === '';
             }
             if (preg_match('/^regexp\\s*:\\s*(.*)/i', $content, $matches)) {
                 return (bool) preg_match($matches[1], $node->text());
             }
             return strstr($node->text(), $content) !== false;
         });
     }
     $found = count($crawler);
     if (is_numeric($count)) {
         self::assertEquals($count, $found, $message);
     } else {
         if (is_bool($count)) {
             $found = $found > 0;
             if ($count) {
                 self::assertTrue($found, $message);
             } else {
                 self::assertFalse($found, $message);
             }
         } else {
             if (is_array($count) && (isset($count['>']) || isset($count['<']) || isset($count['>=']) || isset($count['<=']))) {
                 if (isset($count['>'])) {
                     self::assertTrue($found > $count['>'], $message);
                 }
                 if (isset($count['>='])) {
                     self::assertTrue($found >= $count['>='], $message);
                 }
                 if (isset($count['<'])) {
                     self::assertTrue($found < $count['<'], $message);
                 }
                 if (isset($count['<='])) {
                     self::assertTrue($found <= $count['<='], $message);
                 }
             } else {
                 throw new PHPUnit_Framework_Exception('Invalid count format');
             }
         }
     }
 }
開發者ID:phpunit,項目名稱:phpunit-dom-assertions,代碼行數:69,代碼來源:DOMTestCase.php

示例2: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var FormatterHelper $formatter */
     $formatter = $this->getHelper('formatter');
     $crawlerXml = new Crawler(file_get_contents(__DIR__ . '/test.xml'));
     $output->writeln($formatter->formatBlock('Sibling test', 'question', true));
     $crawlerXml->filter('node')->siblings()->each(function (Crawler $node) use($output) {
         $output->writeln(sprintf('<info>%s</info>', $node->text()));
     });
     $output->writeln($formatter->formatBlock('Test adding content', 'question', true));
     $crawler = new Crawler('<root><node id="1" /><node id="2" /></root>');
     $document = new \DOMDocument();
     $document->loadXML('<root><node id="3" /><node id="4" /></root>');
     $crawler->addDocument($document);
     $crawler->filter('node')->each(function (Crawler $node) use($output) {
         $output->writeln($node->nodeName() . ' ' . $node->attr('id'));
     });
 }
開發者ID:GrizliK1988,項目名稱:symfony-certification-prepare-project,代碼行數:18,代碼來源:DomCrawlerTestCommand.php

示例3: testAddDocument

 public function testAddDocument()
 {
     $crawler = new Crawler();
     $crawler->addDocument($this->createDomDocument());
     $this->assertEquals('foo', $crawler->filterXPath('//div')->attr('class'), '->addDocument() adds nodes from a \\DOMDocument');
 }
開發者ID:sapwoo,項目名稱:portfolio,代碼行數:6,代碼來源:CrawlerTest.php

示例4: testAddDocument

 /**
  * @covers Symfony\Component\DomCrawler\Crawler::addDocument
  */
 public function testAddDocument()
 {
     if (!class_exists('Symfony\\Component\\CssSelector\\CssSelector')) {
         $this->markTestSkipped('The "CssSelector" component is not available');
     }
     $crawler = new Crawler();
     $crawler->addDocument($this->createDomDocument());
     $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addDocument() adds nodes from a \\DOMDocument');
 }
開發者ID:rouffj,項目名稱:symfony,代碼行數:12,代碼來源:CrawlerTest.php

示例5: getXmlContent

 public function getXmlContent($filename, $parentTag)
 {
     $opts = array('http' => array('header' => 'Accept-Charset: UTF-8, *;q=0'));
     $context = stream_context_create($opts);
     $document = new \DOMDocument();
     $fileData = file_get_contents($filename, false, $context);
     $document->loadXML($fileData);
     $crawler = new Crawler();
     $crawler->addDocument($document);
     $content = $crawler->filter($parentTag)->children();
     ini_set('MAX_EXECUTION_TIME', -1);
     return $content;
 }
開發者ID:kozmon,項目名稱:teachme,代碼行數:13,代碼來源:UtilityService.php


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