[英]Html parse for Windows Phone Silverlight 8.1
我正在做Windows Phone 8.1的Silverlight項目,我真的不明白如何解析單個網頁。 我的代碼是這樣的:
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);
,出現錯誤,提示我缺少using語句。 你能幫我嗎?
您缺少using語句。 首先,這是該錯誤告訴您的內容。
嘗試
new HtmlAgilityPack.HtmlWeb().Load(html);
或添加
using HtmlAgilityPack;
與其他參考文獻一起放在班上
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.