我想在我的Laravel 4应用程序中使用CssSelector,我没有安装该类,因为Laravel似乎已经将它放在这个文件夹中:
/供应商/ symfony的/ CSS-选择器/ Symfony的/组件/ CssSelector
所以我尝试使用此演示代码from the doc:
use Symfony\Component\CssSelector\Parser;
$document = new \DOMDocument();
$document->loadHTMLFile('http://fabien.potencier.org/articles');
$xpath = new \DOMXPath($document);
foreach ($xpath->query(Parser::cssToXpath('div.item > h4 > a')) as $node)
{
printf("%s (%s)\n", $node->nodeValue, $node->getAttribute('href'));
}
但是我收到了这个错误:
未找到类'Symfony \ Component \ CssSelector \ Parser'
所以我的问题是,我如何在Laravel中使用CssSelector /这个类?
答案 0 :(得分:4)
您使用的是不存在的类。这不是
use Symfony\Component\CssSelector\Parser;
这是
use Symfony\Component\CssSelector\CssSelector;
routes.php
<?php
use Symfony\Component\CssSelector\CssSelector;
Route::get('test', function() {
echo "<h3>Hello</h3>";
print CssSelector::toXPath('h3');
});
详细了解CssSelector here