php - Simple HTML DOM returning NULL -
i'm scraping data website using simple html dom parser (http://simplehtmldom.sourceforge.net/)
the html is:
<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 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>
and php:
include_once('simple_html_dom.php'); $html = file_get_html('-the url of search query on website-'); $array = array(); foreach($html->find('.productlisting-odd, .productlisting-even') $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);
for reason, value of 'price' keeps returning null. other values collected properly. can't figure out why happening, since elements seem have same structure.
thanks in advance!
most html parsed has non-unicode charset. , problem since json_encode()
works utf-8 encoding. data parsed has ascii characters doesn't lead problem. price data (6th column) contains non-ascii character '€' on json_encode()
fails (and return null).
Comments
Post a Comment