Click here to Skip to main content
15,886,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How come price and availability keeps returning the same value from the first loop?

C#
HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();
html.Load("test.htm");

foreach (HtmlNode row in html.DocumentNode.SelectNodes("//*[@id=\"product_list\"]/li/div[2]/h3/a"))
{
     HtmlNode price = row.SelectSingleNode("//*[@id=\"product_list\"]/li/div[3]/div/span[1]");
     HtmlNode available = row.SelectSingleNode("//*[@id=\"product_list\"]/li/div[3]/div/span[2]");


Thanks
Posted
Comments
FrostedSyntax 16-May-15 23:27pm    
It is allowed to use single quotes around your attribute values instead of escaped double quotes.
Ex. row.SelectSingleNode("//*[@id='product_list']/li/div[3]/div/span[1]");
FrostedSyntax 17-May-15 17:12pm    
Also, for correct xpath syntax you should use a dot before the selector when selecting elements inside another element (not the document element)

1 solution

I've answered you here[^], on one of your previous questions.

Actually I just noticed that you posted multiple questions for the same subject, in the future please don't do that, that is not allowed in CodeProject and your questions can easily get closed due to it.
 
Share this answer
 
Comments
theadmin 24-May-15 0:12am    
Thanks Mario, I figured I would post the question in its own thread instead of combining it and it was not related.
theadmin 24-May-15 13:02pm    
Mario, how do I get in touch with you? I looked at how you came to the answer but its so different when looking at other pages. This stuff is so confusing especially when you are not a software developer.
Mario Z 25-May-15 3:12am    
Hi, you can get in touch with me here, just reply to one of my previous messages or as you already have you can send a direct message and I will reply as soon as I can.
Note that I will continue this discussion regarding your issue on that other post of yours because it will be more relevant there to what I will try to explain.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900