Saya mengambil data dari situs web menggunakan parser DOM HTML Sederhana (http://simplehtmldom.sourceforge.net/ )
HTMLnya adalah:
<tr class="productListing-odd">
<td align="right" class="productListing-data"> 0 </td>
<td class="productListing-data"> <a href="http://www.spellvault.net/p46563/Liliana-of-the-Veil/product_info.html" onmouseout="hd()" onmouseover="sd('images/101257121.jpg')">Liliana of the Veil</a> <br> </td>
<td align="center" class="productListing-data"> Black </td>
<td align="center" class="productListing-data"> Mythic </td>
<td align="center" class="productListing-data"> Innistrad </td>
<td align="right" class="productListing-data">€42,50 </td>
<td align="center" class="productListing-data"><input type="text" name="var[46563]" value="" size="4"> <span class="nowrap"><span class="template-button-left"> </span><span class="template-button-middle"><input class="submitButton" type="submit" value="Bestel"></span><span class="template-button-right"> </span></span> </td>
</tr>
Dan phpnya:
include_once('simple_html_dom.php');
$html = file_get_html('-the url of the search query on the website-');
$array = array();
foreach($html->find('.productListing-odd, .productListing-even') as $element) {
$row = array(
'name' => strip_tags($element->childNodes(1)->innertext),
'set' => strip_tags($element->childNodes(4)->innertext),
'price' => strip_tags($element->childNodes(5)->innertext),
'stock' => strip_tags($element->childNodes(0)->innertext)
);
array_push($array, $row);
}
echo json_encode($array);
Untuk beberapa alasan, nilai 'harga' terus menghasilkan NULL. Semua nilai lainnya dikumpulkan dengan benar. Saya tidak tahu mengapa hal ini terjadi, karena semua elemen tampaknya memiliki struktur yang sama.
Terima kasih sebelumnya!
strip_tags($element->childNodes(1)->innertext)
daripada$element->childNodes(1)->plaintext
? - person Enissay   schedule 01.02.2014$element->find('td[2] a', 0)->text()
- person pguardiario   schedule 01.02.2014