Cannot get availabe products information using PHP Simple HTML DOM

I am trying to get some information from this web page: https://www.ebay.com/itm/Front-strut-spacers-30mm-for-Ford-Focus2-C-Max-Focus3-Kuga-Escape-Lift-Kit/112460641185?epid=19025000547&hash=item1a2f2d33a1:g:0IYAAOSw1m9atFcz. Here is a screenshot:

enter image description here

I want to extract the “10 available” info and I am using the span id qtySubTxt , however my code does not reach the actual value. Here is my code:

   $available = $html->find("#qtySubTxt", 0);
            //var_dump($available);
            if($sold != null){
                $item['available'] = $available->plaintext;
            }else{
                $item['available'] = '';
            }

I debugged the DOM element but I am confused how to reach the text. Here is my debugged info from the DOM element:

enter image description here

php dom

You seem to have A LOT of simple DOM questions lately… but yet you never come back to reply after answers are given?

Told you before about a different approach then how YOU are using the ‘find’ method…

There is also a nested sub SPAN tag that holds your inner text.

            $available = $html->getElementById("qtySubTxt");
            var_dump($available);
            if($available != null){
                $item['available'] = trim($available->nodeValue);
                //var_dump($item['available']);
            }else{
                $item['available'] = '';
            }

I found a solution but it stills returns Null for the $item['available']

Several things…

1.) not sure why you changed to getElementById?

2.) The eBay auction listing is actually invalid markup. You are only supposed to have 1 id (ID’s are supposed to be unique)… however… for whatever reason they are listing ‘2’ DOM elements with the same ID

3.) Had you looked over my last attempt to help in your other SIMPLE DOM thread… you would have seen the answer there as well…

This work just fine for me:

(pretty simple)

include('simplehtmldom/simple_html_dom.php');
$html = file_get_html('https://www.ebay.com/itm/Front-strut-spacers-30mm-for-Ford-Focus2-C-Max-Focus3-Kuga-Escape-Lift-Kit/112460641185');
$available = $html->find('#qtySubTxt')[1];
echo $available;

`

getElementById:

Returns *null* if no elements with the specified ID exists.

An ID should be unique within a page. However, if more than one element with the specified ID exists, the getElementById() method returns the first element in the source code.
Sponsor our Newsletter | Privacy Policy | Terms of Service