我试图从网站上检索一些图片,在我尝试解析图片之前,当我通过检查时,HTML包含100%的来源。该网站包含3个图像,循环也为图像循环3次,但没有检索到任何值。
Array [ <img>, <img>, <img> ]
我没有看到任何可能阻止这种情况的事情,范围和标题都能正常运作。我还使用Firefox控制台检查了xpath,结果如下:(https://image.prntscr.com/image/oZVszoriROWV4Vf8whvWqw.png)。结果是:
<ul id="j-sku-list-1" class="sku-attr-list util-clearfix" data-sku-prop-id="14">
<li class="item-sku-image"><a data-role="sku" data-sku-id="193" id="sku-1-193" title="Black" href="javascript:;" data-spm-anchor-id="2114.10010108.1000016.1"><img src="https://ae01.alicdn.com/kf/HTB1T1vCXnZRMeJjSspnq6AJdFXam/GONTHWID-Gothic-Letters-Embroidery-Middle-Finger-Fleece-Hoodies-Mens-Casual-Patchwork-Sweatshirts-Male-Hip-Hop-Casual.jpg_50x50.jpg" title="Black" bigpic="https://ae01.alicdn.com/kf/HTB1T1vCXnZRMeJjSspnq6AJdFXam/GONTHWID-Gothic-Letters-Embroidery-Middle-Finger-Fleece-Hoodies-Mens-Casual-Patchwork-Sweatshirts-Male-Hip-Hop-Casual.jpg_640x640.jpg"></a></li>
<li class="item-sku-image"><a data-role="sku" data-sku-id="175" id="sku-1-175" title="Green" href="javascript:;" data-spm-anchor-id="2114.10010108.1000016.2"><img src="https://ae01.alicdn.com/kf/HTB13UcvXtZLL1JjSZFPq6xAoFXaq/GONTHWID-Gothic-Letters-Embroidery-Middle-Finger-Fleece-Hoodies-Mens-Casual-Patchwork-Sweatshirts-Male-Hip-Hop-Casual.jpg_50x50.jpg" title="Green" bigpic="https://ae01.alicdn.com/kf/HTB13UcvXtZLL1JjSZFPq6xAoFXaq/GONTHWID-Gothic-Letters-Embroidery-Middle-Finger-Fleece-Hoodies-Mens-Casual-Patchwork-Sweatshirts-Male-Hip-Hop-Casual.jpg_640x640.jpg"></a></li>
<li class="item-sku-image"><a data-role="sku" data-sku-id="366" id="sku-1-366" title="Yellow" href="javascript:;" data-spm-anchor-id="2114.10010108.1000016.3"><img src="https://ae01.alicdn.com/kf/HTB1Zj.wXuALL1JjSZFjq6ysqXXaO/GONTHWID-Gothic-Letters-Embroidery-Middle-Finger-Fleece-Hoodies-Mens-Casual-Patchwork-Sweatshirts-Male-Hip-Hop-Casual.jpg_50x50.jpg" title="Yellow" bigpic="https://ae01.alicdn.com/kf/HTB1Zj.wXuALL1JjSZFjq6ysqXXaO/GONTHWID-Gothic-Letters-Embroidery-Middle-Finger-Fleece-Hoodies-Mens-Casual-Patchwork-Sweatshirts-Male-Hip-Hop-Casual.jpg_640x640.jpg"></a></li>
</ul>
三张图片,这里是网站本身的HTML代码: (https://image.prntscr.com/image/TI_JoY9xTD6-MH4jVMrwwA.png)
public function XPath($html, $xpath){
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($html);
$xdom = new DOMXPath($dom);
libxml_use_internal_errors(false);
$xpathresult = $xdom->query($xpath);
return $xpathresult;
}
XPATH是有效的,我的HTML代码确实包含图像和来源,一切都是一样的。我真的不明白我错过的一切对我来说都很好。
其他信息:
$ this-&gt; xpath:
0 0 0 0 1 1 1 1 2 2 2 2 0 0 0 0 1 1 1 1 2 2 2 2 ... etc
我之前从未遇到过这个问题,getAttribute工作正常。