HTML parsing with C # .net

I am trying to parse the following HTML file, I would like to get the key value. This is done for a Silverlight phone for Windows.

<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 on where to go from here?

thank

+45
html c # windows-phone-7
May 19 '11 at 18:27
source share
2 answers

Let HTMLAgilityPack look. Its a pretty decent HTML parser

http://html-agility-pack.net/?z=codeplex

======

Here is the code to run (error checking required)

 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; } 
+66
May 19 '11 at 18:30
source share

You can use a regex ( Regex class ) for it. The expression might login.html\?key=[^"]* something like this: login.html\?key=[^"]*

+1
May 19 '11 at 18:30
source share



All Articles