1

I am trying to parse an online calendar to have the events posted on that calendar display in my cross-platform app. This is the code that I have so far.

 var html = @"http://html-agility-pack.net/";
 HtmlWeb web = new HtmlWeb();
 HtmlDocument htmldoc = new HtmlAgilityPack.HtmlDocument();
 var htmlDoc = web.LoadFromWebAsync(html);
 HtmlNodeCollection node=htmlDoc.DocumentNode.SelectSingleNode("//body");

The error I am getting is:

"'Task HtmlDocument' does not contain a definition for "DocumentNode' and no extension method 'DocumentNode' accepting a first argument of type 'Task HtmlDocument' could be found (are you missing a using directive or an assembly reference?"

I installed HtmlAgilityPack using the NuGet package manager in Xamarin so it is in my references for the entire project and I am using "using HtmlAgilityPack;" I viewed the HAP in the object browser and there is clearly a "DocumentNode"property which is why I am confused as to why it doesn't think there is.

I don't know what it is that I am missing, please help.

2
  • 2
    you need to await the LoadFromWebAsync() method. Commented Feb 8, 2018 at 20:30
  • 1
    This is one of the pitfalls of using var to define variables - you sometimes assume the type is something other than what it is. Task<Abc> is completely different that Abc. Commented Feb 8, 2018 at 20:39

1 Answer 1

1

you need to use await when calling an async method

// htmlDoc is a Task<HtmlDocument>
var htmlDoc = web.LoadFromWebAsync(html);

// htmlDoc is a HtmlDocument
var htmlDoc = await web.LoadFromWebAsync(html);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.