-1

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.

4

2 回答 2

3

转到下面的链接以下载网站的图标。

打开链接并单击另存为图像以下载它。

http://www.google.com/s2/favicons?domain=codegena.com

将 codegena.com 替换为您要为其下载网站图标的域名。

于 2015-09-21T04:17:19.287 回答
0
<link rel="icon" type="image/png" href="http://yourblog.com/favicon.png" />

<link rel="shortcut icon" href="http://example.com/favicon.ico" type="image/x-icon" />

实际上,添加 favicon 的正确方法是通过插件,因此添加的 favicon 不依赖于主题。

此外,您可能会丢失某些文件类型。

于 2013-06-20T07:53:46.710 回答