用C#.NET HTML解析 [英] Parsing HTML with c#.net

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

问题描述

我试图解析以下的HTML文件,我想一开始键的值。这是正在Silverlight的完成为Windows手机。

I'm trying to parse the following HTML file, I'd like the get the value of key. This is being done on Silverlight for Windows phone.

<HTML>
<link ref="shortcut icon" href="favicon.ico">
<BODY>
<script Language="JavaScript">
location.href="login.html?key=UEFu1EIsgGTgAV7guTRhsgrTQU28TImSZkYhPMLj7BChpBkvlCO11aJU2Alj4jc5"
</script>
<CENTER><a href="login.html?key=UEFu1EIsgGTgAV7guTRhsgrTQU28TImSZkYhPMLj7BChpBkvlCO11aJU2Alj4jc5">Welcome</a></CENTER></BODY></HTML>

任何想法是在哪里何去何从?

any idea's on where to go from here?

感谢

推荐答案

给这个HTMLAgilityPack进去一看。它是一种pretty像样的HTML解析器

Give the HTMLAgilityPack a look into. Its a pretty decent HTML parser

HTTP://htmlagilitypack.$c$cplex.com/

==

下面是一些code让你开始(需要错误检查)

Here's some code to get you started (requires error checking)

HtmlDocument document = new HtmlDocument(); 
string htmlString = "<html>blabla</html>";
document.LoadHtml(htmlString);
HtmlNodeCollection collection = document.DocumentNode.SelectNodes("//a");
foreach (HtmlNode link in collection)
{
     string target = link.Attributes["href"].Value;
}

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

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