我使用PhantomJS迭代网页并获取某些值,例如产品的图片数量。
我的问题是图片似乎没有出现在Pagesource中,所以我无法获得它们。
我认为只有在运行脚本时才会显示图像。
当我检查页面元素时,我可以看到以下内容:
<div class="pdp-images accessibility" tabindex="-1">
<img src="http://kingfisher.scene7.com/is/image/Kingfisher/8007842805253_01c?$PROMO_60_60$" alt="Indesit BIMDS23BIXS Electric Eye Level Double Oven: Image 1">
<img src="http://kingfisher.scene7.com/is/image/Kingfisher/8007842805253_07c?$PROMO_60_60$" alt="Indesit BIMDS23BIXS Electric Eye Level Double Oven: Image 2">
<img src="http://kingfisher.scene7.com/is/image/Kingfisher/8007842805253_02c?$PROMO_60_60$" alt="Indesit BIMDS23BIXS Electric Eye Level Double Oven: Image 3">
</div>
但是,当我访问PhantomJSDriver并查看Pagesource时,它们不存在。
而是有以下内容:
<div class="pdp-viewer" style="position: relative;">
<script id="pdp-viewer" type="text/mustache"> Item <span id="pdp-viewer-counter-current">{{currItem}}</span> of <span id="pdp-viewer-counter-total">{{totalItems}}</span>
然后我查看了具有以下内容的页面源:
<div class="pdp-viewer">
<div class="media-player" data-s7-viewer="s7MixedMediaViewer"
data-asset="Kingfisher/8007842805253_01c;;advanced_image;,Kingfisher/8007842805253_07c;;advanced_image;,Kingfisher/8007842805253_02c;;advanced_image;" data-width="" data-height="">
<div class="pdp-viewer-counter"></div>
<div class="pdp-images accessibility" tabindex="-1">
<img src="http://kingfisher.scene7.com/is/image/Kingfisher/8007842805253_01c?$PROMO_60_60$" alt="Indesit BIMDS23BIXS Electric Eye Level Double Oven" />
<img src="http://kingfisher.scene7.com/is/image/Kingfisher/8007842805253_07c?$PROMO_60_60$" alt="Indesit BIMDS23BIXS Electric Eye Level Double Oven" />
<img src="http://kingfisher.scene7.com/is/image/Kingfisher/8007842805253_02c?$PROMO_60_60$" alt="Indesit BIMDS23BIXS Electric Eye Level Double Oven" />
</div>
</div>
<script id="pdp-viewer" type="text/mustache">
Item
<span id="pdp-viewer-counter-current">{{currItem}}</span>
of
<span id="pdp-viewer-counter-total">{{totalItems}}</span>
</script>
我正在尝试使用以下方式获取图像:
result.ImagesCount = driver.FindElementsByCssSelector("pdp-images.accessibility img").Count;
但由于它们不存在于PhantomJS驱动程序Pagesource中,因此无法实现。
我正在查看的页面如下:
https://spring.io/blog/2014/05/23/preview-spring-security-test-web-security