![](/img/trans.png)
[英]How to use PHP Simple DOM Parser for a div that has an id and class?
[英]Find div that has no class and no id in PHP Simple HTML DOM Parser
我正在使用PHP Simple HTML DOM解析器,它運行良好,但是在選擇沒有ID AND CLASS的div
遇到了問題。
$html->find( 'div[!class]' )
將返回所有沒有類但可以有ID的div。
我嘗試了這個但沒有成功。
$html->find( 'div[!class][!id]' )
提前致謝。
嘗試這個:
$html->find( 'div[!class], div[!id]' )
如果您看解析器的代碼,我認為它沒有這種功能。
function find($selector, $idx=null, $lowercase=false)
{
$selectors = $this->parse_selector($selector);
if (($count=count($selectors))===0) return array();
$found_keys = array();
// find each selector-here it checks for each selector rather than combined one
for ($c=0; $c<$count; ++$c)
{
所以你可以做的是
$find = $html->find('div[!class]');
$selected = array();
foreach ($find as $element) {
if (!isset($element->id)) {
$selected[] = $element;
}
}
$find = $selected;
因此,現在查找將具有所有沒有id和class的元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.