[HTMLAgilityPack]Using HAP with Windows Store Apps – ASync

Hello

I just finished playing around with the HAP library. I wrote the class that gets a lot of info from the website. It works fine with the console application, which I tested the API with, but when it comes to Windows Store App, it seems it doesn't support sync actions, and I have to convert everything to ASync.

Take this code for example:

List<FFSubcategory> ffs = new List<FFSubcategory>(); HtmlWeb web = new HtmlWeb(); HtmlDocument category = web.Load("http://ift.tt/1LXVPz2; + this.link); HtmlNode subcategoriesTable = category.DocumentNode.SelectSingleNode("//div[@id='list_output']"); HtmlNodeCollection subcategoriesRaw = subcategoriesTable.SelectNodes("table/tr/td/div"); foreach(HtmlNode subcategory in subcategoriesRaw) { ffs.Add(new FFSubcategory(subcategory.Element("a").InnerText, subcategory.Element("a").GetAttributeValue("href", "-"), Regex.Match(subcategory.Element("span").InnerText, @"(\d{1,3}\.\d{1,2}[Kk]|\d{1,4}[kK]|\d{1,3})").Groups[1].Value)); } return ffs; 

How can I replace ".SelectSingleNode"/".SelectNodes", and all the rest?

With the beginning, I decided to go with this for now:

List<FFSubcategory> ffs = new List<FFSubcategory>(); HtmlWeb web = new HtmlWeb(); Task<HtmlDocument> Wcategory = web.LoadFromWebAsync("http://ift.tt/1LXVPz2; + this.link); HtmlDocument category = await Wcategory; 

… but what about the rest of the code?

by MrReynevan2 via /r/csharp

Leave a Reply