I am trying extract the favicon from the website url. I am using HtmlAgilityPack
. I get some favicons but not all. I think the problem is variation in implementation. Current strategy of mine is..
HtmlNode imageNode = head.SelectSingleNode("//link[@rel='shortcut icon' or @rel='apple-touch-icon' or @rel='icon' or @rel='apple-touch-icon-precomposed'] | //link[@type='image/png' or @type='image/gif' or @type='image/vnd.microsoft.icon']");
imageNode = head.SelectSingleNode("link[@rel='image_src']");
and the open graph method
private LinkDetails GetOpenGraphInfo(LinkDetails linkDetails, HtmlNode head)
{
foreach (HtmlNode headNode in head.ChildNodes)
{
switch (headNode.Name.ToLower())
{
case "link": break;
case "meta":
if (headNode.Attributes["property"] != null && headNode.Attributes["content"] != null)
{
switch (headNode.Attributes["property"].Value.ToLower())
{
case "og:title":
linkDetails.Title = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
break;
case "og:type":
linkDetails.Type = headNode.Attributes["content"].Value;
break;
case "og:url":
linkDetails.Url = headNode.Attributes["content"].Value;
break;
case "og:image":
linkDetails.Image = new ImageLink(headNode.Attributes["content"].Value, linkDetails.Url);
break;
case "og:site_name":
linkDetails.SiteName = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
break;
case "og:description":
linkDetails.Description = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
break;
case "og:email":
linkDetails.Email = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
break;
case "og:phone_number":
linkDetails.PhoneNumber = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
break;
case "og:fax_number":
linkDetails.FaxNumber = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
break;
}
}
break;
}
}
return linkDetails;
}
but still I am missing some favicons. So I need to know how else are the favicon coded.