Я собираю данные с веб-сайта с помощью парсера Simple HTML DOM (http://simplehtmldom.sourceforge.net/ )
HTML-код:
<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>
И пхп:
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);
По какой-то причине значение «цена» продолжает возвращать NULL. Все остальные значения собираются правильно. Я не могу понять, почему это происходит, поскольку все элементы имеют одинаковую структуру.
Заранее спасибо!
strip_tags($element->childNodes(1)->innertext)
вместо$element->childNodes(1)->plaintext
? - person Enissay   schedule 01.02.2014$element->find('td[2] a', 0)->text()
- person pguardiario   schedule 01.02.2014