0

I am trying to get the value of an image using this code:

image = doc.querySelector("img.product-pic-image").getAttribute("src");

I keep getting null.

Here is the DOM:

DOM

Please help. Here is the link of the product: http://www.aliexpress.com/item/Aluminium-alloy-Pedal-for-Toyota-Mark-X-Reiz-AT-Stainless-Rubber-antiskid-Gas-accelerator-pedal-Brake/32571226955.html?spm=2114.13010208.99999999.261.YEDcC7

I am trying to access it from this page, once added to the cart: http://shoppingcart.aliexpress.com/shopcart/shopcartDetail.htm?spm=2114.13010208.99999999.90000003

Thanks.

10
  • document not doc Commented Mar 16, 2016 at 13:21
  • Have you verified that doc.querySelector("img.product-pic-image") at least returns the image? I'm not sure what doc is, but did you mean document? Commented Mar 16, 2016 at 13:21
  • As stated by j08691 please make sure your using document.querySelector, not doc.querySelector. https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector Commented Mar 16, 2016 at 13:28
  • 3
    The content of that page is sand boxed in an iframe, you won't be able to access it using the page's dom. document gives you access to the pages, dom, each iframe has their own encapsulated dom. Commented Mar 16, 2016 at 13:30
  • Yes. meant document....it doesn't return anythingl Commented Mar 16, 2016 at 13:33

1 Answer 1

1

Try this snippet, it may help you:

var x = document.getElementsByClassName("product-pic-image")[0].src;
Sign up to request clarification or add additional context in comments.

3 Comments

It returns undefined... @hacketo
have you tried the edited question with index in the end:
it picks the image an index zero...I want to pick all the images...how to do this? @Godfather

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.