$xpath = Parser::cssToXpath('h1.foo'); This component is a port of the Python lxml library, which is copyright Infrae and distributed under the BSD license.
Author: Fabien Potencier (fabien@symfony.com)
示例#1
0
 public function testParseExceptions()
 {
     $parser = new Parser();
     try {
         $parser->parse('h1:');
         $this->fail('->parse() throws an Exception if the css selector is not valid');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Symfony\\Component\\CssSelector\\SyntaxError', $e, '->parse() throws an Exception if the css selector is not valid');
         $this->assertEquals("Expected symbol, got '' at h1: -> ", $e->getMessage(), '->parse() throws an Exception if the css selector is not valid');
     }
 }
示例#2
0
 /**
  * Filters the list of nodes with a CSS selector.
  *
  * This method only works if you have installed the CssSelector Symfony Component.
  *
  * @param string $selector A CSS selector
  *
  * @return Crawler A new instance of Crawler with the filtered list of nodes
  *
  * @throws \RuntimeException if the CssSelector Component is not available
  */
 public function filter($selector)
 {
     if (!class_exists('Symfony\\Component\\CssSelector\\Parser')) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException('Unable to filter with a CSS selector as the Symfony CssSelector is not installed (you can use filterXPath instead).');
         // @codeCoverageIgnoreEnd
     }
     return $this->filterXPath(CssParser::cssToXpath($selector));
 }