Videos
Fetching Amazon Product Image by ASIN
I am fetching product image for different ASIN using below link , till end of December 2023 this link was working but now it is not displaying image. Can some please help us out in this, any kind of help will be appreciated ASAP .Thanks
*URL--*
https://ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&MarketPlace=US&ASIN=""&ServiceVersion=20070822&ID=AsinImage&WS=1&Format=SL75
Use should find match by:
scan(/https?:\/\/(?:www\.|)amazon\.com\/(?:gp\/product|[^\/]+\/dp|dp)\/([^\/]+)/)
If you are going to do a lot of URL parsing, I'd recommend looking at the Addressable::URI gem. It will make it a lot easier to maintain than parsing URLs with regex. Take a look at its Template module too, which is designed just for this purpose.
Look at the examples on the main Addressable page for more information.
You could also use Ruby's built-in URI module, to get the path using path, along with a simple string split and some logic to look at which element has the "dp" and then take the next element in the array or "gp" and take the second following element.
Amazon's detail pages can have several forms, so to be thorough you should check for them all. These are all equivalent:
http://www.amazon.com/Kindle-Wireless-Reading-Display-Generation/dp/B0015T963C
http://www.amazon.com/dp/B0015T963C
http://www.amazon.com/gp/product/B0015T963C
http://www.amazon.com/gp/product/glance/B0015T963C
They always look like either this or this:
http://www.amazon.com/<SEO STRING>/dp/<VIEW>/ASIN
http://www.amazon.com/gp/product/<VIEW>/ASIN
This should do it:
var url = "http://www.amazon.com/Kindle-Wireless-Reading-Display-Generation/dp/B0015T963C";
var regex = RegExp("http://www.amazon.com/([\\w-]+/)?(dp|gp/product)/(\\w+/)?(\\w{10})");
m = url.match(regex);
if (m) {
alert("ASIN=" + m[4]);
}
Since the ASIN is always a sequence of 10 letters and/or numbers immediately after a slash, try this:
url.match("/([a-zA-Z0-9]{10})(?:[/?]|$)")
The additional (?:[/?]|$) after the ASIN is to ensure that only a full path segment is taken.
Two options:
1) This is Amazon's API for images by their ASIN You need to create an AssociateTag first
2) This works for the UK store: https://ws-eu.amazon-adsystem.com/widgets/q?_encoding=UTF8&MarketPlace=GB&ASIN=B06Y64P1DG&ServiceVersion=20070822&ID=AsinImage&WS=1&Format=SL250
2a) for US Store: https://ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&MarketPlace=US&ASIN=B07HS3Y5KH&ServiceVersion=20070822&ID=AsinImage&WS=1&Format=SL250
replace B06Y64P1DG with your ASIN
you can also change that size up to a maximum of 500. Some images may have additional white padding, but that can be removed with the AC parameter (auto-crop maybe?)
https://ws-eu.amazon-adsystem.com/widgets/q?_encoding=UTF8&MarketPlace=GB&ASIN=B07HS3Y5KH&ServiceVersion=20070822&ID=AsinImage&WS=1&Format=SL500
https://ws-eu.amazon-adsystem.com/widgets/q?_encoding=UTF8&MarketPlace=GB&ASIN=B07HS3Y5KH&ServiceVersion=20070822&ID=AsinImage&WS=1&Format=AC_SL500