HTML解析库为.NET [英] HTML Parsing Libraries for .NET

查看:160
本文介绍了HTML解析库为.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找库来解析HTML提取链接,表格,标签等。

I'm looking for libraries to parse HTML to extract links, forms, tags etc.

  • http://www.majestic12.co.uk/projects/html_parser.php
  • http://www.netomatix.com/Products/DocumentManagement/HtmlParserNet.aspx
  • http://www.developer.com/net/csharp/article.php/2230091

LGPL或任何其他商业发展的友好许可证是preferable。

LGPL or any other commercial development friendly licenses are preferable.

你有与该某个库的经验吗?或者,你能推荐其他类似的库?

Have you got any experience with one of this libraries? Or could you recommend another similar library?

推荐答案

HTML敏捷性包恰好有这种类型的事情的例子,并使用XPath熟悉的疑问 - 例如(从主页),发现所有的链接很简单:

The HTML Agility Pack has examples of exactly this type of thing, and uses xpath for familiar queries - for example (from home page), to find all links is simply:

foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a@href")) {
    //...
}


修改

截至2012/6/19,在code以上,以及在 HTML敏捷性包的例子 页将无法正常工作。只需要如下图所示略有调整。

HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");

foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
{
  HtmlAttribute att = link.Attributes["href"];
  att.Value = Foo(att); // fix the link
}
doc.Save("file.htm");

这篇关于HTML解析库为.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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