I'm trying to scrap the data-old-hires
and data-a-dynamic-image
element from the below source:
<img alt="Honeywell Long-Life Pure HEPA QuietCare Air Purifier, 17000"
src="http://ecx.images-amazon.com/images/I/61qtgZMjVDL._SX425_.jpg"
data-old-hires="http://ecx.imagesamazon.com/images/I/61qtgZMjVDL._SL1280_.jpg" class="a-dynamic-image a-stretch-vertical" id="landingImage"
data-a-dynamic-image="{"http://ecx.images-amazon.com/images/I/61qtgZMjVDL._SX466_.jpg":[466,466],"http://ecx.images-amazon.com/images/I/61qtgZMjVDL._SX425_.jpg":[425,425],"http://ecx.images-amazon.com/images/I/61qtgZMjVDL._SY450_.jpg":[450,450],"http://ecx.images-amazon.com/images/I/61qtgZMjVDL._SX522_.jpg":[522,522],"http://ecx.images-amazon.com/images/I/61qtgZMjVDL._SY355_.jpg":[355,355]}" style="max-height: 416px; max-width: 416px;">
But I'm getting an error stating that old
and hires
which belong to data-old-hires
are undefined variables. Kindly help me retrieve data-old-hires
and data-a-dynamic-image
elements.
Here is the code:
$html = file_get_html($url);
foreach($html->find('img[alt="Honeywell Long-Life Pure HEPA QuietCare Air Purifier, 17000"]') as $element) {
//echo $element->src . '<br>';
echo $element->data-old-hires.'<br>';
echo $element->data-a-dynamic-image.'<br>';
}