none
Grab ASIN Number from product Url RRS feed

  • Question

  • I have been working on a c# app that works with amazon affiliate API. currently I use the itemlookup method to get a product's details but I am stuck On the App, a user is expected to paste a product link, then the app will grab the ASIN number from the link and then query the API my challenge is how to get the ASIN number from the pasted link. I have come across regex but time is really against me to start learning all about regex. If anyone can help with a regex pattern or any other method that can be useful to grab the ASIN number from the pasted link. Thank You
    Sunday, February 4, 2018 3:58 PM

Answers

  • The Uri object didn't work, I was able to come across a regex pattern @"(/([a-zA-Z0-9]{10})(?:[/?]|$))" that did the job. Thank you very much for your contribution
    • Marked as answer by ebukeez Monday, February 5, 2018 2:37 AM
    Monday, February 5, 2018 2:37 AM

All replies

  • Show some examples and the expected results.

    Sunday, February 4, 2018 4:56 PM
  • For example with this link "https://www.amazon.com/BEAUTBRIDE-Womens-Beaded-Wedding-Fingerless/dp/B010Q0Y92I"

    it should be able to grab just "B010Q0Y92I ".

    or with this link "https://www.amazon.ca/Armani-Exchange-AX2164-Analog-Display/dp/B00VB71TVU?pd_rd_wg=8jp5e&pd_rd_r=4b9329dc-8229-4ffd-b13d-1c8baa51472e&pd_rd_w=EiYgV&ref_=pd_gw_simh&pf_rd_r=ZPMKHPTTSWZBWGZ1XP6N&pf_rd_p=f52db510-19a3-5a54-add4-62c82ff200de"

    it should be able to grab just "B00VB71TVU".

    Thank You

    Sunday, February 4, 2018 6:50 PM
  • Try this method (without Regular Expressions):

    string example1 = "https://www.amazon.com/BEAUTBRIDE-Womens-Beaded-Wedding-Fingerless/dp/B010Q0Y92I";
    Uri u = new Uri( example1 );
    string result1 = u.Segments.Last();
    
    Console.WriteLine( result1 );
    
    string example2 = "https://www.amazon.ca/Armani-Exchange-AX2164-Analog-Display/dp/B00VB71TVU?pd_rd_wg=8jp5e&pd_rd_r=4b9329dc-8229-4ffd-b13d-1c8baa51472e&pd_rd_w=EiYgV&ref_=pd_gw_simh&pf_rd_r=ZPMKHPTTSWZBWGZ1XP6N&pf_rd_p=f52db510-19a3-5a54-add4-62c82ff200de";
    u = new Uri( example2 );
    string result2 = u.Segments.Last();
    
    Console.WriteLine( result2 );
    
    

    Sunday, February 4, 2018 8:52 PM
  • Hello ebukeez,

    The provided links seems that have unified structure ".../dp/ASIN/...". If so, the regex could be this.

            static void Test(string Url) {
    
                Regex regex = new Regex(@"/dp/\w+");
                Match match = regex.Match(Url);
    
                if (match.Success)
                {
                    Console.WriteLine("ISBN:  {0}", match.Value.Split('/').Last());              
                }
            }

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 5, 2018 2:35 AM
    Moderator
  • The Uri object didn't work, I was able to come across a regex pattern @"(/([a-zA-Z0-9]{10})(?:[/?]|$))" that did the job. Thank you very much for your contribution
    • Marked as answer by ebukeez Monday, February 5, 2018 2:37 AM
    Monday, February 5, 2018 2:37 AM