php - XPATH - Get src value of a image from an external webpage
one text
Using this code, I tried to retrieved the image from a web page. It worked for similar web pages but not for this link. As I'm new to scraping it somewhat hard to identify the issue.
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
$doc->strictErrorChecking = false;
$doc->recover = true;
ini_set('user_agent', 'My-Application/2.5');
libxml_use_internal_errors(true);
$doc->loadHTMLFile('https://www.net-a-porter.com/en-us/shop/product/veronica-beard/clothing/blouses/isabel-checked-cotton-blend-top/16114163150514635');
$xpath = new DOMXPath($doc);
$imgs = $xpath->query('//*[@class="Image18__image Image18__image--undefined "]');
foreach($imgs as $img)
{
echo 'ImgSrc: https:' . $img->getAttribute('src') .'<br />' . PHP_EOL;
}
If dd($imgs) I get this,
DOMNodeList {#1795 ?�?
+length: 0
}
Source