【发布时间】:2011-11-08 10:57:43
【问题描述】:
我需要解析从服务器接收到的 HTML 字符串。
<html>
<head/>
<body style="margin: 0;padding: 0">
<a href="http://itunes.apple.com/WebObjects/MZStore.woa
/wa/viewSoftware?id=319737742&mt=8&uo=6" style="margin: 0;padding: 0"><img
src="https://s3.amazonaws.com/sportschatter/postcard.jpg" style="margin: 0;padding:
0"/></a>
</body>
</html>
这是我从服务器得到的响应。我需要检索img URL https://s3.amazonaws.com/sportschatter/postcard.jpg 以及href 部分。
我有 WP7 的 HTML 敏捷包,但我不知道如何编写查询来获取此信息。我尝试过这样的事情:
HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
document.LoadHtml(htmlString);
var value = document.DocumentNode.Descendants("img src").
Select(
x =>
x.InnerText);
这没有给我任何价值。我也试过Regex:
string parseString = htmlstring;
Regex expression = new Regex(@".*img src=(\d+).*$");
Match match = expression.Match(parseString);
MessageBox.Show(match.Groups[1].Value);
但这也不起作用。请让我知道我做错了什么。
【问题讨论】:
-
我也看过很多 html Agility 的例子,其中大多数使用 SelectNodes 方法,该方法在库的 WP7 版本中不存在
标签: c# windows-phone-7 html-parsing