get image src with simple-html-dom

2019-05-11 17:13发布

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.

1条回答
姐就是有狂的资本
2楼-- · 2019-05-11 17:44

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;
查看更多
登录 后发表回答