public async void ReadHTMLPage(string uri, string apiCommand, object data, ParseHtmlSettings settings, Action <List <ParsedHtmlNode> > successCallback, Action <string> errorCallback = null) { try { var htmlWeb = new HtmlWeb(); var html = await htmlWeb.LoadFromWebAsync(uri); var classes = html.DocumentNode.Descendants().Where(d => d.Attributes.Contains(settings.Attribute) && (!settings.HasAttributeValue || d.Attributes[settings.Attribute].Value.Contains(settings.AttributeValue)) ); List <ParsedHtmlNode> nodes = new List <ParsedHtmlNode>(); foreach (HtmlNode node in classes) { ParsedHtmlNode parsedNode = new ParsedHtmlNode(settings.Attribute, node.InnerText); if (!settings.HasInclusion || node.InnerText.Contains(settings.ContentInclusion)) { nodes.Add(parsedNode); } } if (successCallback != null) { successCallback(nodes); } } catch (Exception ex) { if (errorCallback != null) { errorCallback(ex.Message); } } }
public void AddNode(ParsedHtmlNode node) { childNodes.Add(node); }