I have a problem that i don't understand why it's happening. On some elements where i have data-thumb inside img it won't grab the image src element and i can't figure out why.
Here is an example how html page is formatted. Let's call it somepage.com/search?q=singing
<div class="videos">
<div class="thumbWrapper">
<div class="postThumbnail">
<img id="2019485" class="videoThumb" width="190" height="143" alt="some post title" src="http://imageurl.com/uploaded/image/3.jpg" category="7">
</div>
</div>
<div class="thumbWrapper">
<div class="postThumbnail">
<img id="2019485" class="videoThumb" width="190" height="143" alt="some post title" data-thumb="http://imageurl.com/uploaded/image/3.jpg" src="http://imageurl.com/uploaded/image/3.jpg" category="7">
</div>
</div>
<div class="thumbWrapper">
<div class="postThumbnail">
<img id="2019485" class="videoThumb" width="190" height="143" alt="some post title" data-thumb="http://imageurl.com/uploaded/image/3.jpg" src="http://imageurl.com/uploaded/image/3.jpg" category="7">
</div>
</div>
<div class="thumbWrapper">
<div class="postThumbnail">
<img id="2019485" class="videoThumb" width="190" height="143" alt="some post title" src="http://imageurl.com/uploaded/image/3.jpg" category="7">
</div>
</div>
</div>
You see that there is data-thumb on some images, this is totally random, some have that, some not, on a same page.
Here is how i grab a page
$get = curl_init();
curl_setopt($get, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($get, CURLOPT_URL, 'somepage.com/search?q=singing');
curl_setopt($get, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($get, CURLOPT_CONNECTTIMEOUT, 10);
$str = curl_exec($get);
curl_close($get);
$URL = str_get_html($str);
And this works or at least i see it works, next step is to extract elements from page and get those thumbs.
foreach($URL->find('div[class="thumbWrapper"]') as $video) {
$thumb = $video->find('img[class="videoThumb"]');
$image = $thumb[0]->src;
}
And there i get the problem, on img elements where i have
data-thumb
It won't get an image.
On the simplehtmldom page it just says that i need to use like
$video->find('img');
$thumb->src;
But it won't work, i had to specify img class and use a [0] of an array. But i guess when there is data-thumb array is shifted so src is not more [0] in an array?
I don't know i just started using simplehtmldom and still learning, any suggestions?