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);
        }
示例#4
0
 public static HtmlFormComponent GetForm(this HtmlParser htmlParser, ParseBy parseBy)
 {
     return(GetForms(htmlParser.Html, parseBy.Value, parseBy.ParseByType.GetDescription())
            .FirstOrDefault());
 }
示例#5
0
 public static IList <HtmlFormComponent> GetForms(this HtmlParser htmlParser, ParseBy parseBy)
 {
     return(GetForms(htmlParser.Html, parseBy.Value, parseBy.ParseByType.GetDescription()));
 }
示例#6
0
 public HtmlSingleNodeResult FromSingleNode(ParseBy parseBy)
 {
     return(HtmlResultExtensions.ExtractSingleNode(Html, parseBy));
 }
示例#7
0
 public HtmlNodeCollectionResult FromNodeCollection(ParseBy parseBy)
 {
     return(HtmlResultExtensions.ExtractNodeCollection(Html, parseBy));
 }