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


C# HtmlDocument.LoadHtml方法代码示例

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


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

示例1: TestCallingExistingMember

 public void TestCallingExistingMember()
 {
     var doc = new HtmlDocument();
     doc.LoadHtml("<html><body class=\"asdfasd\"><p>asdf asdf sdf</p></body></html>");
     dynamic docElement = doc.DocumentNode;
     var item = docElement.Closed;
     Assert.IsInstanceOf<bool>(item);
 }
开发者ID:AlexanderByndyu,项目名称:HtmlAgilityPack,代码行数:8,代码来源:DynamicTests.cs

示例2: TestCallingExistingFunction

 public void TestCallingExistingFunction()
 {
     var doc = new HtmlDocument();
     doc.LoadHtml("<html><body class=\"asdfasd\"><p>asdf asdf sdf</p></body></html>");
     dynamic docElement = doc.DocumentNode;
     var item = docElement.Descendants();
     Assert.IsInstanceOf<IEnumerable<HtmlNode>>(item);
 }
开发者ID:AlexanderByndyu,项目名称:HtmlAgilityPack,代码行数:8,代码来源:DynamicTests.cs

示例3: TestGetMember

 public void TestGetMember()
 {
     var doc = new HtmlDocument();
     doc.LoadHtml("<html><body><p>asdf asdf sdf</p></body></html>");
     dynamic docElement = doc.DocumentNode;
     var item = docElement.Html.Body;
     Assert.IsNotNull(item);
     Assert.IsInstanceOf<HtmlNode>(item);
 }
开发者ID:AlexanderByndyu,项目名称:HtmlAgilityPack,代码行数:9,代码来源:DynamicTests.cs

示例4: TestGetAttribute

 public void TestGetAttribute()
 {
     var doc = new HtmlDocument();
     doc.LoadHtml("<html><body class=\"asdfasd\"><p>asdf asdf sdf</p></body></html>");
     dynamic docElement = doc.DocumentNode;
     var item = docElement.Html.Body._Class;
     Assert.IsNotNull(item);
     Assert.IsInstanceOf<HtmlAttribute>(item);
 }
开发者ID:AlexanderByndyu,项目名称:HtmlAgilityPack,代码行数:9,代码来源:DynamicTests.cs

示例5: ConvertHtml

        public string ConvertHtml(string html)
        {
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(html);

            StringWriter sw = new StringWriter();
            ConvertTo(doc.DocumentNode, sw);
            sw.Flush();
            return sw.ToString();
        }
开发者ID:AlexanderByndyu,项目名称:HtmlAgilityPack,代码行数:10,代码来源:HtmlConvert.cs

示例6: EnsureAttributeOriginalCaseIsPreserved

 public void EnsureAttributeOriginalCaseIsPreserved()
 {
     var html = "<html><body><div AttributeIsThis=\"val\"></div></body></html>";
     var doc = new HtmlDocument
                   {
                       OptionOutputOriginalCase = true
                   };
     doc.LoadHtml(html);
     var div = doc.DocumentNode.Descendants("div").FirstOrDefault();
     var writer = new StringWriter();
     div.WriteAttributes(writer, false);
     var result = writer.GetStringBuilder().ToString();
     Assert.AreEqual(" AttributeIsThis=\"val\"", result);
 }
开发者ID:ivanovevgeny,项目名称:HtmlAgilityPack,代码行数:14,代码来源:HtmlNode.Tests.cs

示例7: LoadHtmlAsXml

        /// <summary>
        /// Returns an XML document from a given URL.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <param name="url">The URL.</param>
        /// <param name="format">The format.</param>
        /// <param name="absolutizeLinks">if set to <c>true</c> [absolutize links].</param>
        /// <returns></returns>
        public static XmlDocument LoadHtmlAsXml(HtmlWeb web, string url, string format,
            bool absolutizeLinks)
        {
            // Declare necessary stream and writer objects
            MemoryStream m = new MemoryStream();
            XmlTextWriter xtw = new XmlTextWriter(m, null);

            // Load the content into the writer
            if (format == "html")
            {
                web.LoadHtmlAsXml(url, xtw);
                // Rewind the memory stream
                m.Position = 0;
                // Create, fill, and return the xml document
                XmlDocument xdoc = new XmlDocument();
                string content = (new StreamReader(m)).ReadToEnd();

                HtmlDocument doc = new HtmlDocument();
                doc.OptionOutputAsXml = true;
                doc.LoadHtml(content);

                if (absolutizeLinks == true)
                {
                    AttributeReferenceAbsolutizer.ExecuteDefaultAbsolutization
                        (doc.DocumentNode, url);
                }

                xdoc.LoadXml(doc.DocumentNode.OuterHtml);

                return xdoc;
            }
            else
            {
                HtmlDocument doc = web.Load(url);
                doc.OptionOutputAsXml = true;
                XmlDocument xdoc = new XmlDocument();

                if (absolutizeLinks == true)
                {
                    AttributeReferenceAbsolutizer.ExecuteDefaultAbsolutization
                        (doc.DocumentNode, url);
                }

                xdoc.LoadXml(doc.DocumentNode.OuterHtml);

                return xdoc;
            }
        }
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:56,代码来源:HtmlHelper.cs

示例8: GetHtmlNode

        public HtmlNode GetHtmlNode()
        {
            var doc = new HtmlDocument();
            doc.LoadHtml(DomHtml);
            doc.Tag = this;
            var req = Requests.First(x => x.IsFirst);
            if (RedirectUrl != null) req = Requests.FirstOrDefault(x => x.Url == DomUrl);
            if (req != null)
            {
#if NATIVE_HTTP
                if (req.ResponseHeaders == null) throw new System.Net.WebException("Unknown navigation error.");
#else
                if (req.ResponseHeaders == null) throw new System.Net.Reimpl.WebException("Unknown navigation error.");
#endif
                foreach (var header in req.ResponseHeaders)
                {
                    doc.DocumentNode.SetAttributeValue("header-" + header.Key, header.Value);
                }
            }


            foreach (var cook in Cookies)
            {
                doc.DocumentNode.SetAttributeValue("cookie-" + cook.Key, cook.Value);
            }
            doc.SetPageUrl(DomUrl);
            doc.DocumentNode.SetAttributeValue("date-retrieved", DateTime.UtcNow.ToString("o"));
            doc.DocumentNode.SetAttributeValue("requested-url", RequestedUrl);

            foreach (var noscript in doc.DocumentNode.DescendantsAndSelf("noscript").ToList())
            {
                noscript.Remove();
            }

            return doc.DocumentNode;

        }
开发者ID:antiufo,项目名称:Shaman.Http,代码行数:37,代码来源:PageExecutionResults.cs

示例9: RetrieveAccessCode

        private static string RetrieveAccessCode(string authorizationUrl)
        {
            Process.Start("iexplore", authorizationUrl);
            string appKey = null;
            var shellWindows = new ShellWindows();
            var htmlDocument = new HtmlDocument();
            var ie = GetInternetExplorerInstance(shellWindows);

            var document = ie.Document as HTMLDocument;

            if (document != null)
            {
                HtmlNode elementById = null;
                while (document.readyState != "complete" || elementById == null || !ie.LocationURL.Contains("accounts.google.com/o/oauth2/approval"))
                {
                    htmlDocument.LoadHtml(document.documentElement.innerHTML);
                    elementById = htmlDocument.GetElementById("code");
                    Thread.Sleep(500);
                }
                appKey = elementById.Attributes["value"].Value;
            }

            ie.Quit();
            return appKey;
        }
开发者ID:fortesinformatica,项目名称:CoreSprint,代码行数:25,代码来源:SpreadsheetConfiguration.cs

示例10: CreateNode

 /// <summary>
 /// Creates an HTML node from a string representing literal HTML.
 /// </summary>
 /// <param name="html">The HTML text.</param>
 /// <returns>The newly created node instance.</returns>
 public static HtmlNode CreateNode(string html)
 {
     // REVIEW: this is *not* optimum...
     HtmlDocument doc = new HtmlDocument();
     doc.LoadHtml(html);
     return doc.DocumentNode.FirstChild;
 }
开发者ID:eopeter,项目名称:dmelibrary,代码行数:12,代码来源:HtmlNode.cs

示例11: LoadDocument

 private static HtmlDocument LoadDocument(HTMLDocument document)
 {
     var htmlDocument = new HtmlDocument();
     do
         htmlDocument.LoadHtml(document.documentElement.innerHTML);
     while (document.readyState != "complete");
     return htmlDocument;
 }
开发者ID:fortesinformatica,项目名称:CoreSprint,代码行数:8,代码来源:BrowserDataRetriever.cs


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