-1

ウェブサイトの URL からファビコンを抽出しようとしています。を使用してHtmlAgilityPackいます。いくつかのファビコンを取得しますが、すべてではありません。問題は実装のばらつきだと思います。私の現在の戦略は..

        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']");

そしてオープングラフ法

          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;
}

しかし、まだいくつかのファビコンがありません。そのため、ファビコンが他にどのようにコード化されているかを知る必要があります。

4

2 に答える 2

3

以下のリンクにアクセスして、Web サイトのファビコンをダウンロードします。

リンクを開き、[画像として保存] をクリックしてダウンロードします。

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" />

実際、ファビコンを追加する正しい方法はプラグインを使用することで、追加されたファビコンはテーマに依存しません。

また、一部のファイル タイプが欠落している可能性があります。

于 2013-06-20T07:53:46.710 に答える