I am trying to scrape a few images from a website by using the PHP Simplehtmldom library. Normally the image url is found in the 'src' but in this case the image url is found in the 'data-url'. I am having trouble to access the data-url value and I was hoping some could help me out.
Let's say I have the following code:
<section id="imagesContainer">
<div class="img">
<img data-src="https://example.com/image1.jpg" alt="imageAlt1">
</div>
<div class="img">
<img data-src="https://example.com/image2.jpg" alt="imageAlt2">
</div>
<div class="img">
<img data-src="https://example.com/image3.jpg" alt="imageAlt3">
</div>
</section>
I attempted to extract the image urls from the data-src with the following code but it doesn't return the image url:
foreach($html->find('#imagesContainer') as $imagesContainer) {
foreach($imagesContainer->find('img') as $image) {
echo $image->data-src;
}
}
How can I extract the image url from the data-src? Is it possible with the simplehtmldom or do I need a regex?