Irene T.
Irene T.

Reputation: 1393

get image src with simple-html-dom

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.

Upvotes: 4

Views: 20232

Answers (1)

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89557

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;

Upvotes: 11

Related Questions