scrape ASIN from amazon URL using javascript

前端 未结 16 726
旧巷少年郎
旧巷少年郎 2021-01-30 11:42

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=ATVP         


        
16条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 12:35

    Actually, the top answer doesn't work if it's something like amazon.com/BlackBerry... (since BlackBerry is also 10 characters).

    One workaround (assuming the ASIN is always capitalized, as it always is when taken from Amazon) is (in Ruby):

            url.match("/([A-Z0-9]{10})")
    

    I've found it to work on thousands of URLs.

提交回复
热议问题