C# 是否有 LINQ to HTML 或其他一些好的 .Net HTML 操作 API? [英] C# Is there a LINQ to HTML, or some other good .Net HTML manipulation API?

查看:15
本文介绍了C# 是否有 LINQ to HTML 或其他一些好的 .Net HTML 操作 API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C# WPF 应用程序,它需要使用在网页上作为 HTML 表公开的数据.

I have a C# WPF application that needs to consume data that is exposed on a webpage as a HTML table.

获取后来自这个 url 的灵感 我尝试使用 Linq to Xml 来解析 Html 文档,但这仅在 HTML 文档格式非常好(并且其中没有任何注释或 HTML 实体)时才有效.我已经设法使用这种技术获得了一个有效的解决方案,但它远非理想.

After getting inspiration from this url I tried using Linq to Xml to parse the Html document, but this only works if the HTML document is extremely well formed (and doesn't have any comments or HTML entities inside it). I have managed to get a working solution using this technique, but it is far from ideal.

我正在寻找用于解析 HTML 的解决方案.我以前破解过解决方案",但它们很脆弱.我正在寻找一种强大的解析/操作文档的方法.理想情况下,我希望能够让任务变得像 Javascript/JQuery 一样简单.

I am after a solution that is intended for parsing HTML. I have hacked "solutions" before, but they are brittle. I am after a robust way of parsing/manipulating the document. I'd ideally like something that makes the task as easy as it would be from Javascript/JQuery.

有谁知道用于解析/操作 HTML 的好的 .Net 库或实用程序吗?

Does anyone know of a good .Net library or utility for parsing/manipulating HTML?

推荐答案

即使它不是基于 LINQ, 我建议研究 HTML Agility Pack 来自 CodePlex.

Even though it's not LINQ based, I suggest researching the HTML Agility Pack from CodePlex.

注意:Html Agility Pack 现在支持 Linq to Objects(通过 LINQ to Xml Like 接口)

来自 HTML Agility Pack 页面:

From the HTML Agility Pack page:

这是一个敏捷的 HTML 解析器,它构建了一个读/写 DOM 并支持普通的 XPATH 或 XSLT(你实际上不必了解 XPATH 或 XSLT 来使用它,别担心......).它是一个 .NET 代码库,允许您解析网络之外"的 HTML 文件.解析器对现实世界"格式错误的 HTML 非常宽容.对象模型与 System.Xml 的建议非常相似,但适用于 HTML 文档(或流).

This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).

这篇关于C# 是否有 LINQ to HTML 或其他一些好的 .Net HTML 操作 API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆