Вы написали код для получения пути из атрибута src элемента img.
Я не знаю причину, но не могу получить путь к файлу картинки.
Исходный код для HTML и PHP показан ниже.
Код печатает массив (0) {}.
Пожалуйста, помогите мне.
<div id="itemslider-new">
<div class="owl-wrapper-outer">
<div class="owl-wrapper">
<div class="owl-item">
<div class="item">
<div class="product-image-wrapper" style="max-width:196px;">
<a href="https://www.example.com/japanese/cramshell-cr02002">
<img class="lazyOwl" src="https://www.example.com/media/catalog/product/cache/1/small_image/196x/040ec09b1e35df139433887a97daa66f/c/r/cr02002-1.jpg">
</a>
</div>
</div>
</div>
<div class="owl-item">
<div class="item">
<div class="product-image-wrapper" style="max-width:196px;">
<a href="https://www.example.com/japanese/cramshell-cr02002">
<img class="lazyOwl" src="https://www.example.com/media/catalog/product/cache/1/small_image/196x/040ec09b1e35df139433887a97daa66f/c/r/cr02002-2.jpg">
</a>
</div>
</div>
</div>
<div class="owl-item">
<div class="item">
<div class="product-image-wrapper" style="max-width:196px;">
<a href="https://www.example.com/japanese/cramshell-cr02002">
<img class="lazyOwl" src="https://www.example.com/media/catalog/product/cache/1/small_image/196x/040ec09b1e35df139433887a97daa66f/c/r/cr02002-3.jpg">
</a>
</div>
</div>
</div>
<div class="owl-item">
<div class="item">
<div class="product-image-wrapper" style="max-width:196px;">
<a href="https://www.example.com/japanese/cramshell-cr02002">
<img class="lazyOwl" src="https://www.example.com/media/catalog/product/cache/1/small_image/196x/040ec09b1e35df139433887a97daa66f/c/r/cr02002-4.jpg">
</a>
</div>
</div>
</div>
<div class="owl-item">
<div class="item">
<div class="product-image-wrapper" style="max-width:196px;">
<a href="https://www.example.com/japanese/cramshell-cr02002">
<img class="lazyOwl" src="https://www.example.com/media/catalog/product/cache/1/small_image/196x/040ec09b1e35df139433887a97daa66f/c/r/cr02002-5.jpg">
</a>
</div>
</div>
</div>
</div>
</div>
</div>
Вот как получить путь из атрибута src элемента img.
$url = 'https://www.example.com/japanese';
$timeout = 60;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$result = curl_exec($ch);
curl_close($ch);
$dom = new DOMDocument();
$dom->loadHTML($result);
$xpath = new DOMXPath($dom);
$entries = $xpath->query('//div[@id="itemslider-new"]/div[@class="owl-wrapper-outer"]/div[@class="owl-wrapper"]/div[@class="owl-item"]');
$results = array();
foreach ($entries as $entry) {
$result = array();
$result['img'] = $xpath->query("//img", $entry)->item(0)->getAttribute('src');
$results[] = $result;
}