Sunday, May 12, 2024
120
rated 0 times [  127] [ 7]  / answers: 1 / hits: 20927  / 15 Years ago, thu, november 19, 2009, 12:00:00

Assuming I have an Amazon product URL like so



http://www.amazon.com/Kindle-Wireless-Reading-Display-Generation/dp/B0015T963C/ref=amb_link_86123711_2?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-1&pf_rd_r=0AY9N5GXRYHCADJP5P0V&pf_rd_t=101&pf_rd_p=500528151&pf_rd_i=507846


How could I scrape just the ASIN using javascript?
Thanks!


More From » screen-scraping

 Answers
41

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]);
}

[#98274] Monday, November 16, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
phoebea

Total Points: 607
Total Questions: 100
Total Answers: 78

Location: Netherlands
Member since Thu, Jul 1, 2021
3 Years ago
;