get image src with simple-html-dom

Irene T. picture Irene T. · Jul 7, 2014 · Viewed 15.5k times · Source

hello guys i am using simple_html_dom.php to fetch some data but i cannot grab image src.

My html is:

<div class="image">
<a href="http://example.com/post/367327/oikogeneiarxhs" title="Some Title">
<img class="lazy" src="http://example.com/storage/photos/myimage.jpg" data-original="http://example.com/storage/photos/myimage.jpg" alt="Some Title" style="display: inline;"></a>
</div>

My code is:

$item['title']   = $article->find('.title', 0)->plaintext;
$item['thumb']  = $article->find('.lazy', 0)->src;
$item['details'] = $article->find('p', 0)->plaintext;

Also i tried:

$item['thumb']  = $article->find('.image img', 0)->src;

And

$item['thumb']  = $article->find('.lazy img', 0)->src;

The rest of my code works excellent.

Answer

Casimir et Hippolyte picture Casimir et Hippolyte · Jul 7, 2014

These three ways work well for me:

$item['thumb']  = $article->find('img[class=lazy]', 0)->src;
$item['thumb']  = $article->find('.image img', 0)->src;
$item['thumb']  = $article->find('img.lazy', 0)->src;