0
我正在为Windows Phone 8.1做一个Silverlight项目,我真的无法理解如何解析单个网页。我的代码是这样的:Html解析Windows Phone Silverlight 8.1
var html = @"My Web SIte Url";
//It works if the html var contains the actual code and not the url
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(html);
//If i use this line, i get an error on new HtmlWeb()
var htmlDoc = new HtmlWeb().Load(html);
if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
{
// Handle any parse errors as required
}
else
{
if (htmlDoc.DocumentNode != null)
{
//I'm trying to get the first link for now
HtmlAgilityPack.HtmlNode aNode = htmlDoc.DocumentNode.Descendants("a").FirstOrDefault();
if (aNode != null)
{
string first = aNode.GetAttributeValue("title", "null");
string value = aNode.InnerText;
Console.WriteLine(first);
Console.WriteLine(value);
Console.WriteLine(aNode.OuterHtml);
}
}
}
如果我使用htmlDoc.LoadHtml(html);
,我可以得到它只能工作,如果我有内部html
的HTML代码。如果我使用var htmlDoc = new HtmlWeb().Load(html);
,则会显示错误信息,说我缺少使用语句。你能帮我吗?
不,Windows Phone的错误相同。 – 2014-10-01 16:46:58