Cannot get html attribute using PHP Simple Html DOM

I am tryng to get the ,sold" info from eBay listing- Here is the screenshot: enter image description here

As you can see I want to get ,1 sold" text on the upper right corner of the screen. I am using the class ,vi-txt-underline" to get it, however it is not working. Has anyone knows how this can be done, using other attribute or other way?. Here is the code:

            $sold = $html->find("#vi-text-unSderline", 0);

            if($sold != null){
                $item['sold'] = $sold->find("a", 0)->plaintext;
                $item['sold'] = '';
           I am using an array $item[] because I am also searching  for more info before this part of the code.


Several things.

1.) You have a typo in your selector *class (ie: “#vi-text-unSderline”)
2.) It should be a class ‘.’ and not an ‘#’ in your selector value (ie: “.vi-text-underline”)

I’m not sure why its not working in your approach (after those fixes)… perhaps because when using a class to search? there is no second parameter? (as it already collects all matches?)

This seems to work:


$html = file_get_html('');

$targetLink1 = $html->find('.vi-txt-underline')[0];
echo $targetLink1;

echo '<br><strong>-OR-</strong><br>';

$targetLink2 = $html->find('.vi-txt-underline');
echo $targetLink2[0];
Sponsor our Newsletter | Privacy Policy | Terms of Service