【发布时间】:2021-09-09 19:37:25
【问题描述】:
正如我提到的问题here。我将尝试获取图片网址的替代方法。我想从https://www.matchesfashion.com/products/Adidas-By-Stella-McCartney-Metallic-zebra-print-Primegreen-leggings-1424516 获取产品图片网址,如果您检查产品图片,它可以在<figure></figure> 元素内访问。我做了一些研究并编写了这段代码来从外部网页获取内容。但它没有返回任何东西。
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
$doc->strictErrorChecking = false;
$doc->recover = true;
$doc->loadHTMLFile('https://www.matchesfashion.com/products/Adidas-By-Stella-McCartney-Metallic-zebra-print-Primegreen-leggings-1424516');
$xpath = new DOMXPath($doc);
$var = $xpath->evaluate('string(//figure[@class="iiz"])');
我只需要获取该图像的源 URL,这样我就可以继续我的图像编码过程。提前致谢
【问题讨论】:
-
正确的图片url好像是
https://assetsprx.matchesfashion.com/img/product/920/1424516_1.jpg你为什么不用呢?如果你想要整张幻灯片,最好使用 iframe。 -
@PrafullaKumarSahu 这就是我的目标。获取该网址。我只有需要获取'assetsprx.matchesfashion.com/img/product/920/1424516_1.jpg'的产品页面的网址
-
那么你可以搜索带有
iiz__img类的img元素。
标签: php html laravel domcrawler