N.TW12
N.TW12

Reputation: 261

How to get the image url from a webpage

I have been trying to get the image url from a website, the example page is https://ecat.aptiv.com/product/15304719. Using Chrome inspecting feature, I detect the image is inside class ProductDetailHeader col-xs-2 and the src is

<... src="https://ecat.aptiv.com/images/default-source/ecatalog-images/part_gt-2-8-ph-a-001-png.png?sfvrsn=1d1e47d5_0">

However, when I try to extract the url, there are just null values for src

 Dim elements As Object
 Dim element As Object
 Set elements = IE.Document.getElementsByClassName("ProductDetailHeader col-xs-2")
   For Each element In elements
        Debug.Print element.getAttribute("src")
   Next

I have no problem getting other values but I cannot figure out why I cannot get the url.

Upvotes: 1

Views: 749

Answers (1)

Greg
Greg

Reputation: 4518

The image URL is generated using angular JS. If you view the source it will display:

<div class="ProductDetailHeader col-xs-2" style="width: 20%; float: right;" ng-show="ProductDetail.MainImage">
            <img ng-src="{{ProductDetail.MainImage.URL}}" alt="{{ProductDetail.MainImage.Name}}" />
        </div>

There is an alterative way to get the image url, which is by calling their API directly by preforming a HTTP Get to https://ecat.aptiv.com/json/eCatalogSearch/SearchProducts?filter=All&options=&pageSize=12&search=15304719 (which will return JSON).

Upvotes: 1

Related Questions