I try to do this:
$html = file_get_html ( 'http://www.ebay.com/cln/explorer/_ajax?page=1&ipp=16&catids=37958' );
foreach ( $html->find ( 'div[class="connection"]' ) as $collection ) {
echo "found collections: ".count($collection);
Problem is, the returned file from the AJAX request contains elements encoded like:
<div class=\"collection\" data-collectionid=\"75336256016\">
<div class=\"header\">
Can anyone please help me to transform all the \"
in the DOM object back to the normal "
. Or change the ->find
command to find the right element.
Thanks so much!
The response of the ebay is JSON, but there is a <!-- RlogId t6%60jjpfg%3C%3D%60mb6a54d.47e3-143fd4a3ae7-0x32337a -->
or something like this at the end of the response.
First you need to clean up that string..
Than json_decode .. value of the html key is your html that you need to parse..
Once you cleaned up and json_decode the response the real html you looked for will be on the object named html.. take a look the code below.. I am pretty sure you can use better var names...
include('simplehtmldom/simple_html_dom.php');
$html = file_get_html ( 'http://www.ebay.com/cln/explorer/_ajax?page=1&ipp=16&catids=37958' );
$str = $html->save();
$strparts = explode('<!-- RlogId',$str);
$json = $strparts[0];
$htmlcleanedup = json_decode($json);
$domhtml = str_get_html($htmlcleanedup->html);
$ret = $domhtml->find('div[class=collection]');
echo count($ret);
?>
$html = file_get_html ( 'http://www.ebay.com/cln/explorer/_ajax?page=1&ipp=16&catids=37958' );
$html = stripslashes($html);
var_dump($html);
string '<div class="collection" data-collectionid="75336256016">
<div class="header">' (length=78)
Just use stripslashes()
function: