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


C# HtmlAgilityPack.HtmlDocument类代码示例

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


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

示例1: ParsePage

        public static SteamApp ParsePage(int appId, string html)
        {
            if (string.IsNullOrWhiteSpace(html)) throw new ArgumentNullException(nameof(html));

            try
            {
                var app = SteamApp.NewSteamApp(appId, html);

                var htmlDocument = new HtmlDocument();

                var htmlCleaned = html.Replace("\"", "'");

                htmlDocument.LoadHtml(htmlCleaned);

                var documentNode = htmlDocument.DocumentNode;

                var titleNode = documentNode.SelectSingleNode($"//div[@class='{AppTitleClass}']");

                app.Title = titleNode.InnerHtml.Trim();

                var packageNodes = documentNode.SelectNodes($"//div[@class='{PackageClass}']").ToArray();

                foreach (var packageNode in packageNodes)
                {
                    AddPackage(app, packageNode);
                }

                return app;
            }
            catch (Exception)
            {
                throw new InvalidAppException(appId);
            }
        }
开发者ID:tstepanski,项目名称:SteamScraper,代码行数:34,代码来源:Parser.cs

示例2: RefreshAsync

        /// <summary>
        /// 非同步刷新最新資訊
        /// </summary>
        /// <returns></returns>
        public async Task RefreshAsync() {
            HttpClient client = new HttpClient();
            HtmlDocument HTMLDoc = new HtmlDocument();
            HTMLDoc.LoadHtml(await client.GetStringAsync(DataSource));

            var script = HTMLDoc.DocumentNode.Descendants("script")
                .Where(x => x.InnerHtml?.Length > 0).Select(x => x.InnerHtml).ToArray();

            var tempAry = script.First()
                .Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                .Select((x, i) => new { index = i, item = x })
                .GroupBy(x => Math.Floor(x.index / 4.0));

            this.LastPassed = null;
            this.Delay = new TimeSpan();

            foreach (var item in tempAry) {
                string[] temp = item.Select(x=>x.item).ToArray();
                if(temp[3] == "TRSearchResult.push('x')") {
                    this.LastPassed = await Station.GetStationByNameAsync(
                        innerString(temp[0],"'","'")
                        );
                }                
            }

            var time = new TimeSpan(0, int.Parse(innerString(script.Last(), "=", ";")),0);
            this.Delay= time;
        }
开发者ID:XuPeiYao,项目名称:TwOpenData.Railways,代码行数:32,代码来源:RealTimeTrainInfo.cs

示例3: ParseHtmlAsync

        public async Task<string> ParseHtmlAsync(string tenant, string html)
        {
            var doc = new HtmlDocument();
            doc.LoadHtml(html);

            var nodes = doc.DocumentNode.SelectNodes("//include[@article-alias and @category-alias]");
            if (nodes == null)
            {
                return html;
            }

            foreach (var node in nodes)
            {
                string alias = node.Attributes["article-alias"].Value;
                string categoryAlias = node.Attributes["category-alias"].Value;

                var model =  await ContentModel.GetContentAsync(tenant, categoryAlias, alias).ConfigureAwait(false);
                if (model != null)
                {
                    string contents = model.Contents;

                    var newNode = HtmlNode.CreateNode(contents);
                    node.ParentNode.ReplaceChild(newNode, node);
                }
            }

            return doc.DocumentNode.OuterHtml;
        }
开发者ID:frapid,项目名称:frapid,代码行数:28,代码来源:ArticleExtension.cs

示例4: ReplaceTags

        private string ReplaceTags(string html)
        {
            var doc = new HtmlDocument();
            doc.LoadHtml(html);

            var divs = doc.DocumentNode.Descendants("div").Where(d =>
                d.Attributes.Contains("class")).ToList(); //&& d.Attributes["class"].Value.Contains("editable-wrapper"));


            var editableDivs = new List<HtmlNode>();

            foreach (var div in divs)
            {
                if(div.Attributes["class"].Value.Contains("editable-wrapper"))
                {
                    editableDivs.Add(div);
                }
            }


            foreach (var editableDiv in editableDivs)
            {
                editableDiv.AppendChild(GetEditButtonElement());
                editableDiv.AppendChild(GetSaveButtonElement());
            }

            return doc.DocumentNode.OuterHtml;
        }
开发者ID:Excepti0n,项目名称:misechko.com.ua,代码行数:28,代码来源:ReplaceTagsFilter.cs

示例5: datascraper

        public datascraper()
        {
            string url = @"http://www.bbc.co.uk/sport/football/results/partial/competition-118996114";
            HtmlWeb htmlWeb = new HtmlWeb();
            HtmlDocument doc = new HtmlDocument{ OptionUseIdAttribute = true };

            doc = htmlWeb.Load(url);
            HtmlNodeCollection mtchrslts = doc.DocumentNode.SelectNodes("//tr[@id]");

            string date;
            string ateam;
            string hteam;
            string score;
            string idmess;
            string idnum;
            string[] teamscores;
            string teamscoreh;
            string teamscorea;

            foreach (HtmlNode matchresult in mtchrslts)
            {
                idmess = matchresult.SelectSingleNode("//tr[@id]").Id;
                idnum = idmess.Replace("match-row-", "");
                score = matchresult.SelectSingleNode("//abbr[@title='Score']").InnerText;
                teamscores = score.Split('-');
                teamscoreh = teamscores[0];
                teamscorea = teamscores[1];
                hteam = matchresult.SelectSingleNode("//p[(@class='team-home teams')]").InnerText;
                ateam = matchresult.SelectSingleNode("//p[(@class='team-away teams')]").InnerText;
                date = matchresult.SelectSingleNode("//td[(@class='match-date')]").InnerText;
            }

            return;
        }
开发者ID:mrwebed,项目名称:take1-minimumpoints4safety,代码行数:34,代码来源:datascraperController.cs

示例6: GetLinkFromWebPage

 private async Task<String> GetLinkFromWebPage()
 {
   WebRequest request = WebRequest.CreateHttp(ZERANOE_WEB);
   using (WebResponse response = await request.GetResponseAsync())
   using (Stream s = response.GetResponseStream())
   {
     HtmlDocument doc = new HtmlDocument();
     doc.Load(s);
     HtmlNodeCollection collection = doc.DocumentNode.SelectNodes("/html/body/div[@id='builds-page']/div[@class='grid-460']/a[@class='latest']");
     int bits = Environment.Is64BitProcess ? 64 : 32;
     Regex regex = new Regex($"Download FFmpeg git-\\S+ {bits}-bit Static");
     foreach (var item in collection)
     {
       if (regex.IsMatch(item.InnerText))
       {
         string link = item.GetAttributeValue("href", null);
         if (link != null)
         {
           // Link is not absolute (./win64/ffmpeg.7z)
           if (link.StartsWith("."))
             link = ZERANOE_WEB + link.Substring(2);
           return link;
         }
       }
     }
   }
   return null;
 }
开发者ID:Gazzilow,项目名称:ffmpeg-vp9-wrap,代码行数:28,代码来源:FfmpegLoader.cs

示例7: LoadHtmlTemplate

        private void LoadHtmlTemplate()
        {
            this.document = new HtmlDocument();
            this.document.Load( Assembly.GetExecutingAssembly().GetManifestResourceStream(HtmlTemplate) );

            this.table = new HtmlNodeCollection(document.GetElementbyId(LogEventTableId));
        }
开发者ID:mk83ko,项目名称:any-log-analyzer,代码行数:7,代码来源:HtmlReportGenerator.cs

示例8: Parse

        protected override void Parse(String page)
        {
            var doc = new HtmlDocument();
            doc.LoadHtml(page);

            var nodes = doc.DocumentNode.SelectNodes("//ul[@class='list']//li");
            if (nodes != null)
            {
                foreach (var node in nodes)
                {
                    var sale = false; //из списка нельзя получить инфу о скидке, поэтому всегда false

                    var title = node.SelectSingleNode(".//div[@class='title']").FirstChild.InnerText.Replace("\r\n", " ");
                    var searchString = DelBadChar(ref title);

                    var gameUrl = StoreUrl + node.SelectSingleNode(".//a").GetAttributeValue("href", String.Empty);
                    var cost = node.SelectSingleNode(".//div[@class='price']//span[@class='new']").InnerText;

                    _entries.Add(new GameEntry()
                    {
                        SearchString = searchString,
                        StoreUrl = StoreUrl,
                        Title = title,
                        GameUrl = gameUrl,
                        Cost = cost,
                        Sale = sale
                    });
                }
            }
        }
开发者ID:soramusoka,项目名称:gbn-parser,代码行数:30,代码来源:Shop1cParser.cs

示例9: HeroDataConverter

        public HeroDataConverter()
        {
            agilityPackHelper = new AgilityPackHelper();
            HtmlDocument doc = new HtmlDocument();

            heroesName = GetHeroesName();

            foreach (var heroName in heroesName)
            {
                doc = LoadHeroHtmlPage(heroName);

                skillImages = GetSkillPortraits(doc);
                skillNames = GetSkillNames(doc);
                skillDescriptions = GetSkillDescriptions(doc);
                primaryStatsImages = GetPrimaryStatsImages(doc);
                primaryStatsValues = GetPrimaryStatsValues(doc);
                biography = GetBiography(doc).Trim() ;
                manaCostDictionary = GetManaCost(doc);
                coolDownList = GetCoolDown(doc);
                abilityCastType = GetAbilityCastType(doc);
                skillTargetAffectedType = GetSkillTargetAffectedType(doc);
                skillDamageType = GetSkillDamageType(doc);
                skillVideo = GetSkillVideo(doc);
                skillRemainingValues = GetSkillRemainingValues(doc);

                heroCreator.createHero(heroName, biography);                

                for (int i = 0; i < skillNames.Count; i++)
                {
                    heroCreator.createHeroSkill(skillNames[i], skillDescriptions[i], manaCostDictionary, coolDownList, abilityCastType[i],
                        skillTargetAffectedType[i], skillDamageType[i], skillVideo);
                }
            }
        }
开发者ID:GibranLyra,项目名称:GLyra.Dota2Project,代码行数:34,代码来源:1392068905$HeroDataConverter.cs

示例10: GetFundamentals

        static IDictionary<string, string> GetFundamentals(Uri url)
        {
            string html;
            using (var webClient = new WebClient())
                html = webClient.DownloadString(url);

            var doc = new HtmlDocument
                          {
                              OptionFixNestedTags = true
                          };

            doc.LoadHtml(html);

            var fundamentals = new Dictionary<string, string>();
            var trs = doc.DocumentNode.SelectNodes("//div[@data-ajax-name='EquitySummaryTable']//table[contains(@class, 'horizontalTable')]//tr");

            if (trs == null)
                return fundamentals;

            foreach (var tr in trs)
            {
                var name = tr.Elements("th").Single().InnerText;
                var value = tr.Elements("td").Single().InnerText;

                if (value == "--")
                {
                    Log.DebugFormat("Missing: {0} = {1}", name, value);
                    continue;
                }

                Log.DebugFormat("Found: {0} = {1}", name, value);
                fundamentals.Add(name, value);
            }
            return fundamentals;
        }
开发者ID:rdingwall,项目名称:fundamentals-aggregator,代码行数:35,代码来源:FtDotComSummary.cs

示例11: GetPageCount

        //Получаем общее число страниц
        protected override int GetPageCount(HtmlDocument document, string startAddress)
        {
            HtmlNodeCollection c = document.DocumentNode.SelectNodes("//div[@class='pageNavBar']");
            int pageCount = 1;
            if (c != null)
                foreach (HtmlNode n in c)
                {
                    HtmlNodeCollection cc = n.ChildNodes;
                    if (cc != null)
                    {
                        int i = 0;
                        foreach (HtmlNode nn in cc)
                        {
                            i++;
                            if (i == 6)
                            {
                                pageCount = int.Parse(Regex.Match(nn.InnerText, @"(\d+)").Groups[1].Value);
                            }
                        }
                    }
                    break;
                }

            return pageCount;

        }
开发者ID:molec1,项目名称:MySPM_NewParsers,代码行数:27,代码来源:RentSibdomDataCollector.cs

示例12: ParseTopPerson

 public static void ParseTopPerson(string html, Action<List<Person>> finished)
 {
     BackgroundWorker bw = new BackgroundWorker();
     bw.DoWork += new DoWorkEventHandler((sender, e) =>
     {
         List<Person> TopPerson = new List<Person>();
         HtmlDocument hDoc = new HtmlDocument();
         hDoc.LoadHtml(html);
         var tableRows = hDoc.DocumentNode.SelectNodes(Constants.Instance.XPATH_GAME_TOP_RESULT);
         foreach (var node in tableRows)
         {
             var results = ChildElementsInTableRow(node);
             if (results.Count == Constants.Instance.COUNT_GAME_TOP_RESULT_COLUMNS)
             {
                 var person = TopPersonFromStrings(results);
                 if (person.Total != 0)
                 {
                     TopPerson.Add(person);
                 }
             }
         }
         finished(TopPerson);
     });
     bw.RunWorkerAsync();
 }
开发者ID:nkwsqyyzx,项目名称:BetStrategy,代码行数:25,代码来源:HtmlParser.cs

示例13: ParseRecommends

 public static void ParseRecommends(string html, Action<List<Recommend>> finished)
 {
     BackgroundWorker bw = new BackgroundWorker();
     bw.DoWork += new DoWorkEventHandler((sender, e) =>
     {
         List<Recommend> allRecommends = new List<Recommend>();
         HtmlDocument hDoc = new HtmlDocument();
         hDoc.LoadHtml(html);
         var tableRows = hDoc.DocumentNode.SelectNodes(Constants.Instance.XPATH_GAME_SHOW_RESULT);
         foreach (var node in tableRows)
         {
             var results = ChildElementsInTableRow(node);
             if (results.Count == Constants.Instance.COUNT_GAME_SHOW_RESULT_COLUMNS)
             {
                 var rec = RecommendFromStrings(results);
                 if (IsValidRecommend(rec))
                 {
                     allRecommends.Add(rec);
                 }
             }
         }
         finished(allRecommends);
     });
     bw.RunWorkerAsync();
 }
开发者ID:nkwsqyyzx,项目名称:BetStrategy,代码行数:25,代码来源:HtmlParser.cs

示例14: ConvertHtml

        private void ConvertHtml(ExCSS.Stylesheet sheet, string html, Section section)
        {
            _sheet = sheet;
            if (string.IsNullOrEmpty(html))
            {
                throw new ArgumentNullException("html");
            }

            if (section == null)
            {
                throw new ArgumentNullException("section");
            }

            //section.PageSetup.HeaderDistance = "0.001cm";
            section.PageSetup.FooterDistance = Unit.FromCentimeter(0.01);

 // Create a paragraph with centered page number. See definition of style "Footer".
            var footer = section.Footers.Primary.AddParagraph();
            //section.Footers.Primary.
            footer.Format.Alignment = ParagraphAlignment.Right;
            footer.AddPageField();
            footer.AddText(" of ");
            footer.AddNumPagesField();
            
            var doc = new HtmlDocument();
            doc.LoadHtml(html);
            ConvertHtmlNodes(doc.DocumentNode.ChildNodes, sheet, section);
        }
开发者ID:jgshumate1,项目名称:MigraDoc.Extensions,代码行数:28,代码来源:HtmlConverter.cs

示例15: btnTestCode_Click

        private void btnTestCode_Click(object sender, RoutedEventArgs e)
        {
            var mainPage = GetHtml("http://htmlagilitypack.codeplex.com");
            var homepage = new HtmlDocument();
            homepage.LoadHtml(mainPage);

            var nodes =
                homepage.DocumentNode.Descendants("a").Where(x => x.Id.ToLower().Contains("releasestab")).FirstOrDefault
                    ();
            var link = nodes.Attributes["href"].Value;

            var dc = new HtmlDocument();
            try
            {
                Cursor = Cursors.Wait;
                var req = (HttpWebRequest) WebRequest.Create(link);
                using (var resp = req.GetResponse().GetResponseStream())
                using (var read = new StreamReader(resp))
                {
                    dc.LoadHtml(read.ReadToEnd());
                    var span =
                        dc.DocumentNode.Descendants("span").Where(
                            x => x.Id.ToLower().Contains("releasedownloadsliteral")).FirstOrDefault();
                    MessageBox.Show(
                        int.Parse(span.InnerHtml.ToLower().Replace("downloads", string.Empty).Trim()).ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error loading file: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error,
                                MessageBoxResult.OK);
            }
        }
开发者ID:Clancey,项目名称:HtmlAgilityPack,代码行数:33,代码来源:Window1.xaml.cs


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