如何获取网站的图标? [英] How can I get a web site's favicon?

查看:67
本文介绍了如何获取网站的图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

足够简单的问题:我创建了一个小应用程序,它基本上只是我的系统托盘中的一个收藏夹,以便我可以从同一位置打开常用的站点/文件夹/文件.从我的系统中获取已知文件类型的默认图标并不是非常复杂,但我不知道如何从网站获取 favicon.(例如,地址栏中有灰色->橙色堆栈图标)

Simple enough question: I've created a small app that is basically just a favourites that sits in my system tray so that I can open often-used sites/folders/files from the same place. Getting the default icons from my system for known file types isn't terribly complicated, but I don't know how to get the favicon from a website. (SO has the grey->orange stack icon in the address bar for instance)

有人知道我会怎么做吗?

Does anyone know how I might go about that?

推荐答案

您需要通过几种方式来解决这个问题:

You'll want to tackle this a few ways:

  1. 在域的根目录寻找favicon.ico

www.domain.com/favicon.ico

查找带有 rel="shortcut icon" 属性的 标签

Look for a <link> tag with the rel="shortcut icon" attribute

查找带有 rel="icon" 属性的 标签

Look for a <link> tag with the rel="icon" attribute

后两者通常会产生更高质量的图像.

The latter two will usually yield a higher quality image.

为了涵盖所有基础,有一些特定于设备的图标文件可能会产生更高质量的图像,因为这些设备上的图标通常比浏览器需要的图标大:

Just to cover all of the bases, there are device specific icon files that might yield higher quality images since these devices usually have larger icons on the device than a browser would need:

<link rel="apple-touch-icon" href="images/touch.png"/>

<link rel="apple-touch-icon-precomposed" href="images/touch.png"/>

要下载图标而不关心图标是什么,您可以使用像 http://www 这样的实用程序.google.com/s2/favicons 将完成所有繁重的工作:

And to download the icon without caring what the icon is you can use a utility like http://www.google.com/s2/favicons which will do all of the heavy lifting:

var client = new System.Net.WebClient();

client.DownloadFile(
    @"http://www.google.com/s2/favicons?domain=stackoverflow.com",
    "stackoverflow.com.ico");

这篇关于如何获取网站的图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆