1

使用simple_html_dom.php,我正在尝试从朋友的网站上抓取可用的尺寸。不幸的是,我没有成功提取单一尺寸,因为我不明白正确的选择标准是什么。

在下面的示例中,我想提取“110”,因为它是唯一可用的大小。我尝试提取标签,但后来我想我必须包括下一个标准,这应该是 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>
4

1 回答 1

0

您可以遍历标签并检查输入是否被禁用:

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]'),但您可能会排除具有其他类的标签。

于 2014-08-13T15:10:19.867 回答