I'm doing a Silverlight project for Windows Phone 8.1 and i really can't understand how to parse a single web page. My code is this:
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);
}
}
}
If I use htmlDoc.LoadHtml(html);
, I can get it work only if I have the html code inside html
. If I use var htmlDoc = new HtmlWeb().Load(html);
, I get the error that says that I'm missing a using statement. Can you help me please?
You're missing a using statement. Which is kind of what the error was telling you in the first place.
Try
new HtmlAgilityPack.HtmlWeb().Load(html);
or add
using HtmlAgilityPack;
on the top of your class with other references.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.