Html Agility Pack - how to choose the right range class

I am trying to find the lowest price on Amazon pages. As an example, you can use this URL:

http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=9963BB#/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=E999-4701&rh=i%3Aaps%2Ck%3AE999-4701

I want to find the lowest price ... the number to the right of the "new".

Here is what I tried:

        using (TextWriter tw = new StreamWriter(@"D:\AmazonUrls.txt"))
        {
            foreach (string item in list)
            {
                var webGet = new HtmlWeb();
                var document = webGet.Load(item);
                var lowestPrice = document.DocumentNode.SelectSingleNode("//span[@id='subPrice']");
                if (lowestPrice != null)
                {
                    Console.WriteLine(lowestPrice);                
                }

            }           
        }

I do not get any result. Where am I mistaken?

+3
source share
1 answer

You are requesting nodes with a idsub-rating, but actually classhas a sub-price:

<span class="subPrice">
        <a href="http://rads.stackoverflow.com/amzn/click/B001BA0W06">5 new</a>
    from <span class="price">$245.90</span></span>

so

var lowestPrice = document.DocumentNode.SelectSingleNode("//span[@class='subPrice']");

should get what you want. However, the example page that you give has several nodes that match this pattern, so you need to select several nodes and then scroll through them to decide which one has the lowest priority.

+5
source

All Articles