当前位置: 首页>>代码示例>>C#>>正文


C# HtmlAgilityPack类代码示例

本文整理汇总了C#中HtmlAgilityPack的典型用法代码示例。如果您正苦于以下问题:C# HtmlAgilityPack类的具体用法?C# HtmlAgilityPack怎么用?C# HtmlAgilityPack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HtmlAgilityPack类属于命名空间,在下文中一共展示了HtmlAgilityPack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetPosition

 protected override string GetPosition(HtmlAgilityPack.HtmlNode div)
 {
     return div.Descendants("a").Where(
        d => d.Attributes.Contains("class") &&
        d.Attributes["class"].Value.Contains("rua-b-vacancy-title") || d.Attributes["class"].Value.Contains("jqKeywordHighlight")
        ).Select(d => d.InnerText).First();
 }
开发者ID:ericojonathan,项目名称:tdd.demand,代码行数:7,代码来源:RabotaUaCrawler.cs

示例2: From

        public static XrefDetails From(HtmlAgilityPack.HtmlNode node)
        {
            if (node.Name != "xref") throw new NotSupportedException("Only xref node is supported!");
            var xref = new XrefDetails();
            xref.Uid = node.GetAttributeValue("href", null);
            var overrideName = node.InnerText;
            if (!string.IsNullOrEmpty(overrideName))
            {
                xref.AnchorDisplayName = overrideName;
                xref.PlainTextDisplayName = overrideName;
            }
            else
            {
                // If name | fullName exists, use the one from xref because spec name is different from name for generic types
                // e.g. return type: IEnumerable<T>, spec name should be IEnumerable
                xref.AnchorDisplayName = node.GetAttributeValue("name", null);
                xref.PlainTextDisplayName = node.GetAttributeValue("fullName", null);
            }

            xref.Title = node.GetAttributeValue("title", null);
            xref.Raw = node.GetAttributeValue("data-raw", null);
            xref.ThrowIfNotResolved = node.GetAttributeValue("data-throw-if-not-resolved", false);

            return xref;
        }
开发者ID:ansyral,项目名称:docfx,代码行数:25,代码来源:XrefDetails.cs

示例3: CheckDocResult

 public static ResultType_enum CheckDocResult(HtmlAgilityPack.HtmlDocument doc, out string message)
 {
     try
     {
         message = "";
         if (doc == null)
         {
             message = "Не удается подключиться к сети";
             return ResultType_enum.ErrorNetwork;
         }
         //Не удается отобразить эту страницу
         if (doc.DocumentNode.InnerText.IndexOf("Не удается отобразить эту страницу") > -1)
         {
             message = "Не удается подключиться к сети";
             return ResultType_enum.ErrorNetwork;
         }
         if (doc.DocumentNode.InnerText.IndexOf("Ведутся регламентные работы") > -1)
         {
             message = "Ведутся регламентские работы";
             return ResultType_enum.ReglamentaWork;
         }
         return ResultType_enum.Done;
     }
     catch (Exception ex)
     {
         message = ex.Message + '\n' + ex.StackTrace;
         return ResultType_enum.Error;
     }
 }
开发者ID:BrickProd,项目名称:PublicOrders,代码行数:29,代码来源:Globals.cs

示例4: GetVacancyUrl

 protected override string GetVacancyUrl(HtmlAgilityPack.HtmlNode div)
 {
     var vacancyHref = div.Descendants("a").Where(
         d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("vacancy-title"))
         .Select(d => d.Attributes["href"].Value).SingleOrDefault();
     return BaseUrl + vacancyHref;
 }
开发者ID:ericojonathan,项目名称:tdd.demand,代码行数:7,代码来源:RabotaUaCrawler.cs

示例5: RunActions

 public KeyValuePair<PartsPage, IEnumerable<string>> RunActions(string content, string url, HtmlAgilityPack.HtmlDocument doc)
 {
     Content = content;
       Url = url;
       Doc = doc;
       string res = null;
       var count = 3;
       if (IsPermessionEmail())
       {
     while (string.IsNullOrEmpty(res) || (res.Equals("error") && count > 0))
     {
       LoadCaptcha();
       res = SendMessage();
       count--;
     }
       }
       else
     res = "No Permission";
       var typeResult = PartsPage.MessageSend;
       if (res != null)
       {
     return new KeyValuePair<PartsPage, IEnumerable<string>>(typeResult, new List<string>()
     {
         res
     });
       }
       else
     return new KeyValuePair<PartsPage, IEnumerable<string>>(typeResult, null);
 }
开发者ID:ruslanruslanruslan,项目名称:Parser,代码行数:29,代码来源:AvitoSendMessageToOwner.cs

示例6: AttrValue

 private static string AttrValue(HtmlAgilityPack.HtmlNode htmlNode, string name)
 {
     var attr = htmlNode.Attributes[name];
     return attr != null
         ? attr.Value
         : null;
 }
开发者ID:ZA1,项目名称:HtmlToMarkDown,代码行数:7,代码来源:MarkDownDocument.cs

示例7: GetNode

        /// <summary>
        /// 
        /// </summary>
        /// <param name="node"></param>
        /// <param name="element"></param>
        /// <param name="attribute"></param>
        /// <param name="valuePortion"></param>
        /// <returns></returns>
        public static HtmlAgilityPack.HtmlNode GetNode(HtmlAgilityPack.HtmlNode node,
                                            string element,
                                            string attribute,
                                            string valuePortion,
                                            bool tryNull = false)
        {
            if(tryNull)
            {
                try
                {
                    var _nodes = node.Descendants(element)
                            .Where(d => d.Attributes.Contains(attribute) && d.Attributes[attribute].Value.Contains(valuePortion));

                    if(_nodes != null && _nodes.Count() > 0)
                    {
                        var _node = _nodes.ToArray()[0];//.SingleOrDefault();
                        return _node;
                    }
                }
                catch { }
            }
            else
            {
                var _nodes = node.Descendants(element)
                            .Where(d => d.Attributes.Contains(attribute) && d.Attributes[attribute].Value.Contains(valuePortion));

                if(_nodes != null && _nodes.Count() > 0)
                {
                    var _node = _nodes.ToArray()[0];//.SingleOrDefault();
                    return _node;
                }
            }
            return null;
        }
开发者ID:jcmangubat,项目名称:YPS.Engine,代码行数:42,代码来源:HtmlUtil.cs

示例8: ConvertSelectFields

        public List<ListPicker> ConvertSelectFields(HtmlAgilityPack.HtmlNodeCollection nodes)
        {
            if (nodes == null)
                return null;
            var ret = new List<ListPicker>();
            foreach (var item in nodes)
            {
                ListPicker foo = new ListPicker();
                foo.Name = item.Attributes["Name"].Value;
                foo.HorizontalAlignment = HorizontalAlignment.Stretch;
                var options = item.SelectNodes(".//option");
                var listboxitems = new List<KeyValuePair<string, string>>();
                foreach (var option in options)
                {
                    var bar = new KeyValuePair<string, string>(HttpUtility.HtmlDecode(option.NextSibling.OuterHtml), option.Attributes["value"].Value);
                    listboxitems.Add(bar);
                }
                foo.ItemsSource = listboxitems;
                foo.FullModeItemTemplate = (DataTemplate)Application.Current.Resources["SearchListBoxItemTemplate"];
                foo.ItemTemplate = (DataTemplate)Application.Current.Resources["SearchListBoxItemTemplateSelected"];
                foo.BorderThickness = new Thickness(2.0);
                foo.SelectedIndex = 0;
                ret.Add(foo);

            }
            return ret;
        }
开发者ID:rkrishnasanka,项目名称:Dubizzle,代码行数:27,代码来源:HTMLtoXAML.cs

示例9: ConvertInputFields

        public List<EDAdvancedTextbox> ConvertInputFields(HtmlAgilityPack.HtmlNodeCollection nodes)
        {
            if (nodes == null)
                return null;

            var ret = new List<EDAdvancedTextbox>();
            foreach (var item in nodes)
            {
                EDAdvancedTextbox foo = new EDAdvancedTextbox();
                foo.Name = item.Attributes["Name"].Value;
                try
                {
                    foo.DefaultText = item.Attributes["Title"].Value;
                }
                catch (NullReferenceException)
                {
                    foo.DefaultText = foo.Name;
                }
                foo.HorizontalAlignment = HorizontalAlignment.Stretch;
                foo.BorderBrush = new SolidColorBrush(Colors.Black);
                foo.BorderThickness = new Thickness(2.0);

                ret.Add(foo);
            }
            return ret;
        }
开发者ID:rkrishnasanka,项目名称:Dubizzle,代码行数:26,代码来源:HTMLtoXAML.cs

示例10: ValidateTable

        private void ValidateTable(ValidationEventArgs e, HtmlAgilityPack.HtmlNode table)
        {
            var columns = table.SelectNodes("//th");

            if (columns == null || columns.Count == 0)
            {
                Fail(e, "Could not locate any columns in the table!");
            }
            else
            {
                int columnIndex = FindColumnIndexByName(columns, ColumnName);

                if (columnIndex == -1)
                {
                    Fail(e, String.Format("Could not find a column named '{0}'!", ColumnName));
                }
                else
                {
                    bool foundTheValue = DoesValueExistInColumn(table, columnIndex, ExpectedValue);

                    if (foundTheValue == true)
                    {
                        Pass(e, "Found the column value!");
                    }
                    else
                    {
                        Fail(e, String.Format("Could not find a cell with the value '{0}'", ExpectedValue));
                    }
                }
            }
        }
开发者ID:rderouin,项目名称:test.utilities,代码行数:31,代码来源:TableColumnValueValidator.cs

示例11: AddColumnRowToTable

        public static void AddColumnRowToTable(HtmlAgilityPack.HtmlNode table, string s1, string s2, string s3)
        {
            HtmlAttribute attr = table.OwnerDocument.CreateAttribute("style", "border:1px solid black;border-collapse:collapse;");

            HtmlNode row = table.OwnerDocument.CreateElement("tr");
            row.Attributes.Add(table.OwnerDocument.CreateAttribute("valign", "top"));

            HtmlNode td1 = table.OwnerDocument.CreateElement("td");
            HtmlNode td2 = table.OwnerDocument.CreateElement("td");

            HtmlAttribute rightJustify = table.OwnerDocument.CreateAttribute("align", "right");

            row.Attributes.Add(attr);
            td1.Attributes.Add(attr);
            td2.Attributes.Add(attr);
            td1.Attributes.Add(rightJustify);
            td2.Attributes.Add(rightJustify);

            td1.InnerHtml = s1;
            td2.InnerHtml = s2;

            row.ChildNodes.Add(td1);
            row.ChildNodes.Add(td2);

            if (string.IsNullOrEmpty(s3)==false)
            {
                HtmlNode td3 = table.OwnerDocument.CreateElement("td");
                td3.Attributes.Add(attr);
                td3.Attributes.Add(rightJustify);
                td3.InnerHtml = s3;
                row.ChildNodes.Add(td3);
            }
            table.ChildNodes.Add(row);
        }
开发者ID:mahitosh,项目名称:HRA4,代码行数:34,代码来源:UIUtils.cs

示例12: GetLinesFromCommand

        public int[] GetLinesFromCommand(HtmlAgilityPack.HtmlNode htmlNode, string commandName)
        {
            if (htmlNode == null)
            {
                return null;
            }

            var text = htmlNode.InnerText;
            text = text.Replace("<!--", string.Empty).Replace("-->", string.Empty);
            var command = text.Split(';').Where(s => s.Trim().StartsWith(commandName)).FirstOrDefault();

            if (command == null)
            {
                return null;
            }

            try
            {
                var arguments = command.Split(':')[1];
                var lineRanges = arguments.Split(',');
                var lineSet = new System.Collections.Generic.SortedSet<int>();

                foreach (var range in lineRanges)
                {
                    this.ParseRange(lineSet, range);
                }

                return lineSet.ToArray();
            }
            catch
            {
                return null;
            }
        }
开发者ID:hmeydac,项目名称:Homeworld,代码行数:34,代码来源:CodeSnippetHighlighter.cs

示例13: GrabStoryVariables

        public override string GrabStoryVariables(HtmlAgilityPack.HtmlDocument doc)
        {
            string[] addressParts = storyURL.Split('/');

            try
            {
                storyChapters = (ushort)(doc.DocumentNode.SelectNodes("//div[@id='chapterList']//li").Count() - 1);
                storyTitle = addressParts[3].Replace("_", " ");

                try { authorName = doc.DocumentNode.SelectSingleNode("//h2[@class='textCenter']/a").InnerText; }
                catch { authorName = doc.DocumentNode.SelectSingleNode("//h1[@class='textCenter']/a").InnerText; }

                authorLink = "<a href=\"http://" + addressParts[2] + "\">" + authorName + "</a>";

                HtmlNodeCollection summaryNodes = doc.DocumentNode.SelectNodes("//div[@id='chapterList']//li[1]/p");
                foreach (HtmlNode node in summaryNodes)
                {
                    if (!(node.InnerText.Contains("Word count:") || node.InnerText.Contains("Also available as:")))
                        storySummary += node.InnerText;
                }

                string[] splitHeader = doc.DocumentNode.SelectSingleNode("//div[@id='chapterList']//li[1]/p[1]").InnerText.Split(' ');
                //Grabs individual variables from story, then splits header up for further parsing.

                for (int i = 0; i < splitHeader.Length; i++)
                {//Looks for keywords in header, and if found, assigns them and following section to appropriate story variable.
                    if (splitHeader[i].Contains("Word") && splitHeader[i + 1].Contains("count"))
                        storyWords = "Words: " + splitHeader[i + 2];
                    else if (splitHeader[i].Contains("Status:"))
                    {
                        if (splitHeader[i + 1].Contains("Complete"))
                            storyStatus = "Complete";
                        else
                            storyStatus = "In Progress";
                    }
                }

                splitHeader = doc.DocumentNode.SelectSingleNode("//div[@id='chapterList']//li[2]").InnerText.Split(' ');
                for (int i = 0; i < splitHeader.Length; i++)
                    if (splitHeader[i].Contains("Uploaded"))
                        storyPublished = "Published: " + splitHeader[i + 2] + " " + splitHeader[i + 3] + " " + splitHeader[i + 4];

                splitHeader = doc.DocumentNode.SelectSingleNode("//div[@id='chapterList']//li[" + (storyChapters + 1) + "]").InnerText.Split(' ');
                for (int i = 0; i < splitHeader.Length; i++)
                    if (splitHeader[i].Contains("Uploaded"))
                        storyUpdated = "Updated: " + splitHeader[i + 2] + " " + splitHeader[i + 3] + " " + splitHeader[i + 4];

                for (int i = 2; i <= storyChapters + 1; i++)
                {
                    addressParts = doc.DocumentNode.SelectSingleNode("//div[@id='chapterList']//li[" + i + "]/a[1]").Attributes["href"].Value.Split('/');
                    addressParts[2] = addressParts[2].Replace("__", " - ");
                    addressParts[2] = addressParts[2].Replace("_", " ");
                    chapterTitles.Add(addressParts[2]);
                }
                storyBody = "(//li[@class='chapterDisplay'])";
                return "Story grab success.";
            }
            catch
            { return "Story grab failed! Please verify URL provided is for a story."; }
        }
开发者ID:benroth,项目名称:FanBook,代码行数:60,代码来源:FanFicAuthorsBook.cs

示例14: GetVacancyBody

        protected override string GetVacancyBody(HtmlAgilityPack.HtmlDocument htmlDocument)
        {
            var nodes = htmlDocument.DocumentNode.Descendants("div").Where( r => r.Attributes.Contains("class") && r.Attributes["class"].Value.Equals("description"));
            var body = nodes.Aggregate("", (current, node) => current + node.InnerText);

            return body;
        }
开发者ID:ericojonathan,项目名称:tdd.demand,代码行数:7,代码来源:CareersStackoverfowComCrawler.cs

示例15: Validate

 /// <summary>
 /// 执行所有 HTML 检查
 /// </summary>
 /// <param name="context"></param>
 /// <returns>HTML 检查结果。</returns>
 public static IList<ValidationResult> Validate(this IEnumerable<IValidation> validations, HtmlAgilityPack.HtmlDocument document, HtmlStaticizeContext context)
 {
     if (document == null)
     {
         throw new ArgumentNullException("document");
     }
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (validations == null)
     {
         return null;
     }
     var validationResult = new List<ValidationResult>();
     foreach (var vd in validations)
     {
         var errorMessage = vd.Validate(document, context);
         if (errorMessage != null && errorMessage.Length > 0)
         {
             validationResult.Add(new ValidationResult
             {
                 Uri = context.Uri,
                 ValidationType = vd.Type,
                 Name = vd.Name,
                 Message = errorMessage,
             });
         }
     }
     return validationResult;
 }
开发者ID:darklx,项目名称:Staticize,代码行数:36,代码来源:ValidationExtensions.cs


注:本文中的HtmlAgilityPack类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。