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


C# HtmlDocument.LoadHtml方法代码示例

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


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

示例1: GetVideoLink

        private static async Task<string> GetVideoLink(string link)
        {
            var httpClient = new HttpClient();

            var response = await httpClient.GetStringAsync(link);

            var doc = new HtmlDocument();
            doc.LoadHtml(response);

            var iframeLink = doc.DocumentNode.Descendants("body").
                First().
                Descendants("iframe").
                First().
                Attributes["src"].
                Value;

            response = await httpClient.GetStringAsync(iframeLink);

            doc.LoadHtml(response);

            var videoLink = response.Split('\"').
                Where(part =>
                part.Contains(".mp4") && part.StartsWith(@"http://")).
                FirstOrDefault();

            return videoLink;
        }
开发者ID:SamirHafez,项目名称:Fresh,代码行数:27,代码来源:FreeTVCrawlerService.cs

示例2: 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

示例3: HtmlDocument

        /// <summary>
        /// New html document instance
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public HtmlDocument HtmlDocument(string html)
        {
            var d = new HtmlDocument();
            d.LoadHtml(html);

            return d;
        }
开发者ID:Alchemy86,项目名称:DAS-Desktop,代码行数:12,代码来源:HttpBase.cs

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: CreateRequest

        public static HtmlDocument CreateRequest(string url)
        {
            using (var client = new HttpClient())
            {
                try
                {
                    var response = client.GetAsync(url).Result;

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var responseContent = response.Content.ReadAsStringAsync().Result;

                        var doc = new HtmlDocument();
                        doc.LoadHtml(responseContent);
                        return doc;
                    }
                    else
                    {
                        throw new Exception(response.StatusCode.ToString());
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("Error executing query " + url + ". " + e.Message + " " + e.InnerException);
                }
            }
        }
开发者ID:maxMakaronok,项目名称:Assistent,代码行数:27,代码来源:CommonWebWorker.cs

示例9: 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

示例10: 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

示例11: GetForms

 public IEnumerable<HtmlForm> GetForms()
 {
     var doc = new HtmlDocument();
     doc.LoadHtml(Content);
     var forms = doc.DocumentNode.SelectNodes("//form");
     return forms.Select(HtmlForm.FromNode);
 }
开发者ID:Sjord,项目名称:ScoutsOffline,代码行数:7,代码来源:Response.cs

示例12: 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

示例13: 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

示例14: ItemCrawler

 public ItemCrawler(Uri url)
 {
     _htmlDocument = new HtmlDocument();
     var html = new WebClient().DownloadString(url.OriginalString);
     _htmlDocument.LoadHtml(html);
     _document = _htmlDocument.DocumentNode;
 }
开发者ID:stiano,项目名称:ShopperDopper,代码行数:7,代码来源:ItemCrawler.cs

示例15: 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


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