I am using HtmlAgilityPack to get the meta and othe descriptions of the page. The code works find for the simple websites such as Tumblr., Twitter, Stack Overflow.
But when I try to load major sites, such as Google it shows me just a title as Google and no description tag. Similary for Facebook it shows me no description but for the title it shows me Update your browser | Facebook.
I am new to this package, I downloaded latest version of it from NuGet package in MS WebMatrix. The code I am using is as:
@using HtmlAgilityPack;
@{
Layout = "~/_SiteLayout.cshtml";
var Title = "";
var Description = "";
using(var client = new WebClient()){
var html = client.DownloadString("http://www.facebook.com");
var doc = new HtmlDocument();
doc.LoadHtml(html);
var title = doc.DocumentNode.Descendants("title").FirstOrDefault();
if(title != null){
Title = title.InnerText;
}
var description = doc.DocumentNode.Descendants("meta")
.Where(n => n.GetAttributeValue("name", String.Empty)
.Contains("description")).FirstOrDefault();
if(description != null){
Description = description.GetAttributeValue("content", string.Empty);
}
}
}
This issue, by name, looks like an old browser issue. How to fix this?