AngleSharp 实战(02)之传递 HTML 内容给 AngleSharp
2019-10-29 15:03 音乐让我说 阅读(333) 评论(0) 编辑 收藏 举报文档地址:https://anglesharp.github.io/docs/Examples.html
直接贴代码了:
using System; using System.Linq; using System.Threading.Tasks; using AngleSharp; using AngleSharp.Html.Parser; namespace AngleSharpSamples { class Program { static async Task Main(string[] args) { var config = Configuration.Default.WithDefaultLoader(); var context = BrowsingContext.New(config); //Source to be parsed var source = "<h1>Some example source</h1><p>This is a paragraph element"; //Create a virtual request to specify the document to load (here from our fixed string) var document = await context.OpenAsync(req => req.Content(source)); //Do something with document like the following Console.WriteLine("Serializing the (original) document:"); Console.WriteLine(document.DocumentElement.OuterHtml); var p = document.CreateElement("p"); p.TextContent = "This is another paragraph."; Console.WriteLine("Inserting another element in the body ..."); document.Body.AppendChild(p); Console.WriteLine("Serializing the document again:"); Console.WriteLine(document.DocumentElement.OuterHtml); } } }
谢谢浏览!
作者:音乐让我说(音乐让我说 - 博客园)
出处:http://music.cnblogs.com/
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步