public static HtmlSingleNodeResult ExtractSingleNode(string html, ParseBy parseBy) { var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(html); var singleNode = htmlDocument.DocumentNode.SelectSingleNode(parseBy.BuildXPath()); if (singleNode == null) { return(new HtmlSingleNodeResult { Success = false, HtmlNode = null }); } else { return(new HtmlSingleNodeResult { HtmlNode = singleNode }); } }
public static HtmlNodeCollectionResult ExtractNodeCollection(string html, ParseBy parseBy) { var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(html); var nodeCollection = htmlDocument.DocumentNode.SelectNodes(parseBy.BuildXPath()); if (nodeCollection == null) { return(new HtmlNodeCollectionResult { Success = false, NodeCollection = null }); } else { return(new HtmlNodeCollectionResult { NodeCollection = nodeCollection }); } }
public static HtmlNodeSingleCollectionResult ForEachSingleNode(this HtmlNodeCollectionResult htmlNodeCollectionResult, ParseBy parseBy, bool ensureOnlyNotNull = true) { var singleNodeCollection = new HtmlNodeSingleCollectionResult(); foreach (var node in htmlNodeCollectionResult.NodeCollection) { var partialNode = node.SelectSingleNode(parseBy.Value); if (partialNode == null && ensureOnlyNotNull) { singleNodeCollection.Success = false; } singleNodeCollection.HtmlNodes.Add(partialNode); } return(singleNodeCollection); }
public static HtmlFormComponent GetForm(this HtmlParser htmlParser, ParseBy parseBy) { return(GetForms(htmlParser.Html, parseBy.Value, parseBy.ParseByType.GetDescription()) .FirstOrDefault()); }
public static IList <HtmlFormComponent> GetForms(this HtmlParser htmlParser, ParseBy parseBy) { return(GetForms(htmlParser.Html, parseBy.Value, parseBy.ParseByType.GetDescription())); }
public HtmlSingleNodeResult FromSingleNode(ParseBy parseBy) { return(HtmlResultExtensions.ExtractSingleNode(Html, parseBy)); }
public HtmlNodeCollectionResult FromNodeCollection(ParseBy parseBy) { return(HtmlResultExtensions.ExtractNodeCollection(Html, parseBy)); }