我在Symfony 2中有这样的剧本:
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\DomCrawler\Crawler;
class MyController extends Controller
{
....
foreach($crawler->filter('[type="text/css"]') as $content){
/* make things */
}
foreach($crawler->filter('[rel="stylesheet"]') as $content){
/* make things */
}$crawler->filter能接受不同的条件并在一段时间内完成吗?例如:
foreach($crawler->filter('[rel="stylesheet"] OR [type="text/css"]') as $content){
/* make things */
}发布于 2015-07-09 08:31:25
filter函数采用标准的CSS选择器,因此:
foreach ($crawler->filter('[rel="stylesheet"],[type="text/css"]') as $content) {
/* make things */
}应该做好这份工作。
发布于 2015-07-08 20:34:57
AFAIK这是不可能的,但您可以这样做:
$crawler->filter('[rel="stylesheet"]')->addAll($crawler->filter('[type="text/css"]'));这应该能解决你的问题。
此外,还可以使用xpath进行筛选。
https://stackoverflow.com/questions/31302633
复制相似问题