使用simple_html_dom.php
,我试图从朋友的网站上抓取可用的尺寸。不幸的是,我没有成功地提取出一个单一的尺寸,因为我不明白正确的选择标准是什么
在下面的例子中,我想提取"110",因为它是唯一可用的大小。我试着提取标签,但我想我必须包括下一个criterium,它应该是element_id的值:"for"-以"attribute 6"开头。如果有任何帮助,我们将不胜感激。
<div id="sizeSelector" class="cf">
<div class="titleHeader cf">
<p class="text">
<h2>Choose a Size</h2>
<h2 id="print-size" style="display:none;">Sizes available</h2>
<label for="attribute76">
<input id="attribute76" class="jshide" type="radio" value="76" name="super_attribute[144]">
110
</label>
</div>
</div>
您可以遍历标签并检查输入是否被禁用:
foreach ($html->find('#sizeSelector label') as $e)
{ if ( $e->find('input[disabled]') )
{ // $e is the <label> element, $e->plaintext gets the text content
echo "Input " . $e->plaintext . " is disabled.'n";
}
else
{ echo "Input " . $e->plaintext . " is enabled.'n";
}
}
不幸的是,尝试选择没有禁用类的标签时,使用find('label[class!=disabled]')
似乎会自动取消所有没有类的标签。您可以查询没有类find('label[!class]')
的标签,但可能会排除具有其他类的标签。