4

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.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Irene T.
  • 1,393
  • 2
  • 20
  • 40
  • 1
    Using your HTML snippet your code seems to work fine. What do you want? The full URL? I get `http://example.com/storage/photos/myimage.jpg` when I use your code. – Giacomo1968 Jul 07 '14 at 00:48

1 Answers1

12

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;
Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
  • Hmmm… I am using PHP 5.4 & Simple HTML Dom 1.5 with the code provided. All works as expected. Odd. – Giacomo1968 Jul 07 '14 at 01:14
  • @JakeGould: Yes, but it seems that the example code doesn't really fit to the situation: http://stackoverflow.com/questions/24601807/parsing-xml-with-simplexml-load/24602265#24602265 – Casimir et Hippolyte Jul 07 '14 at 03:52
  • 1
    Ahhh! So the broken clock works twice a day in some scenarios, but it is still not a working clock. Got it. – Giacomo1968 Jul 07 '14 at 04:56