Reputation: 114
hey i am working on a web crawler in ASP.NET and using HTML Agility Pack for HTML Parsing . Whenever I loop Foreach in a table and Want to SELECT and get value of Iteration Node It only Gives me first value repeatedly.
Here is my CODE
public void Olxrun(String query) { string url = "http://olx.com.pk/all-results/?q=" + query + "&page=1" ; var webGet = new HtmlWeb(); var document = webGet.Load(url); try { var lnks = document.DocumentNode.SelectNodes("//*[contains(@class,'offer onclick ')]"); foreach (HtmlNode node in lnks) { Label1.Text += "
" + node.SelectSingleNode("//*[contains(@class,'price x-large margintop10')]").InnerText; } } catch(Exception exa) { Label1.Text += "Error"; } }
Upvotes: 0
Views: 524
Reputation: 2372
Try using .//*[contains(@class,'price x-large margintop10')]
//
will always start from the root element.
.//
will start from the current node.
Upvotes: 2