'HtmlDocument' does not contain a definition for 'GetElementById'

c# html-agility-pack win-universal-app

Question

I'm trying to download a webpage and trying to extract some specific data in Windows Universal Apps. I'm using HtmlAgilityPack I wrote following code segment. But I'm having some error.

    async public void LoadDataFromWeb()
    {
        var client = new HttpClient(); // Add: using System.Net.Http;
        var url = @"http://www.dsebd.org/displayCompany.php?name=NBL";
        string sourcePage = await client.GetStringAsync(url);
        var doc = new HtmlDocument();
        doc.LoadHtml(sourcePage);
        HtmlNode specificNode = doc.GetElementById("nodeId");
        HtmlNodeCollection nodesMatchingXPath = specificNode.DocumentNode.SelectNodes("x/path/nodes");
    }

Error:

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

What might be the problem?

Popular Answer

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

you should use doc.GetElementbyId() instead of doc.GetElementById()

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

i think it can be replaced by

      specificNode.OwnerDocument.DocumentNode

because they both return HtmlNodeCollection

not sure about this though



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why