내 코드에 어떤 문제가 있습니까? 왜 효과가 없습니까? PHP simple_html_dom URL에서 데이터 추출
이
내가 사용하려고 내 코드입니다 :function extract_data($url){
// Create DOM from URL
$html = file_get_html($url);
// initialize empty array to store the data array from each row
$theData = array();
// loop over rows
foreach($html->find('p.ch_title') as $row) {
// initialize array to store the cell data from each row
$rowData = array();
foreach($row->find('p.ch_spec') as $cell) {
// push the cell's text to the array
$rowData[] = $cell->innertext;
}
// push the row's data array to the 'big' array
$theData[] = $rowData;
}
return $theData;
}
을하고이 URL에서 HTML 데이터입니다;
<div class="holder-specificatii">
<div class="box-specificatie">
<div class="ch_group">Dimensiuni</div>
<p class="ch_title">Latime (mm):</p>
<p class="ch_spec">195</p>
<p class="ch_title">Inaltime:</p>
<p class="ch_spec">65</p>
<p class="ch_title">Diametru (inch):</p>
<p class="ch_spec">15</p>
<div class="clear"></div>
</div>
<div class="box-specificatie">
<div class="ch_group">Caracteristici tehnice</div>
<p class="ch_title">Anotimp:</p>
<p class="ch_spec">Iarna</p>
<p class="ch_title">Indice sarcina:</p>
<p class="ch_spec">91</p>
<p class="ch_title">Indice viteza:</p>
<p class="ch_spec">T</p>
<p class="ch_title">Economie de carburant:</p>
<p class="ch_spec">C</p>
<p class="ch_title">Franare pe suprafete umede:</p>
<p class="ch_spec">C</p>
<p class="ch_title">Tip vehicul:</p>
<p class="ch_spec">Turism</p>
<p class="ch_title">DOT:</p>
<p class="ch_spec">2014</p>
<p class="ch_title">Nivel de zgomot (dB):</p>
<p class="ch_spec">72dB</p>
<div class="clear"></div>
</div>
</div>
문제는 빈 배열을 반환하는 기능입니다. 당신은 정의되지 않은 객체를 가리키고
정말 좁혀 야하거나 더 구체적으로해야합니다. – pguardiario
for 루프에서 정의되지 않은'$ table' 객체를 사용하고 있습니까? 그게 당신에게 오류 메시지를 제공해야합니다! –
예, 사소한 문제였습니다. $ table to $ html로 다시 작성했지만 빈 배열을 반환합니다. – m3tsys