[英]Scrape data from website using Simple_HTML_Dom.php
使用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>
您可以遍歷標簽並檢查輸入是否被禁用:
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!=disabled]')
似乎會自動關閉所有沒有類的標簽。 您可以查詢不帶類find('label[!class]')
,但可能會排除具有其他類的標簽。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.