simple html dom:如何获取没有某个属性的标签 [英] simple html dom: how get a tag without certain attribute

查看:414
本文介绍了simple html dom:如何获取没有某个属性的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得class属性等于someclass的标签,但只包含没有定义属性id的标签。

I want to get the tags with "class" attribute equal to "someclass" but only those tags that hasn't defined the attribute "id".

strong>我尝试以下(基于此答案),但没有工作:

I tried the following (based on this answer) but didn't work:

$html->find('.someclass[id!=*]');

注意

我正在使用简单HTML DOM类,并在其提供的基本文档中没有找到我需要的。

I'm using Simple HTML DOM class and in the basic documentation that they give, I didn't find what I need.

推荐答案

简单HTML DOM类不支持 CSS3伪类,这是负属性匹配所必需的。

Simple HTML DOM class does not support CSS3 pseudo classes which is required for negative attribute matching.

很容易解决这个限制,而没有太多麻烦。

It is simple to work around the limitation without much trouble.

$nodes = array_filter($html->find('.something'), function($node){return empty($node->id);});

这篇关于simple html dom:如何获取没有某个属性的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆