当前位置: 首页>>代码示例>>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;未经允许,请勿转载。