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:
What might be the problem?
'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