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.

Carol Kariuki
  • 95
  • 1
  • 1
  • 8
  • `document` not `doc` – j08691 Mar 16 '16 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`? – dmeglio Mar 16 '16 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](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) – Craig Stroman Mar 16 '16 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. – Ron Sims II Mar 16 '16 at 13:30
  • Yes. meant document....it doesn't return anythingl – Carol Kariuki Mar 16 '16 at 13:33
  • You will have to use server side code to request the page contents and parse them server side. It can't be done client side. – Shadow The GPT Wizard Mar 16 '16 at 13:34
  • @RonSimsII there is no way to access iframes? – Carol Kariuki Mar 16 '16 at 13:34
  • @CarolKariuki see : http://stackoverflow.com/questions/1451208/access-iframe-elements-in-javascript – Hacketo Mar 16 '16 at 13:38
  • Thanks @Hacketo but I cant seem to find the iframes id as suggested in the link. Anything to use in place of id? – Carol Kariuki Mar 16 '16 at 13:47
  • You can retrieve the iframe with `document.querySelector` using something that match the iframe (not able to visit your link) – Hacketo Mar 16 '16 at 13:50

1 Answers1

1

Try this snippet, it may help you:

var x = document.getElementsByClassName("product-pic-image")[0].src;
Festim Cahani
  • 317
  • 4
  • 18