我怎样才能得到一个网站的图标? [英] How can I get a web site's favicon?

查看:153
本文介绍了我怎样才能得到一个网站的图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就这么简单的问题:我已经创建一个小的应用程序,基本上只是一个收藏夹,它位于我的系统盘,这样我可以从同一个地方打开常用的网站/文件夹/文件。从获取我的系统默认的图标已知文件类型是不是非常复杂,但我不知道如何从一个网站的图标。 (所以一直比如在地址栏中grey->橙色堆栈图标)

有谁知道我可能会去吗?

解决方案

您将要解决这几个方面:

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

    www.domain.com/favicon.ico

  2. 查找一个<链接> 相对=快捷方式图标属性标记

    <链接REL =快捷方式图标的href =/的favicon.ico/>

  3. 查找一个&LT;链接&GT; 相对=图标属性<标签/ P>

    &LT;链接相对=图标的href =/ favicon.png/&GT;

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


只是为了覆盖所有的基地,也有具体的设备图标可能会产生更高质量的图像,因为这些设备通常有设备不是一个浏览器就需要在更大的图标文件:

&LT;链接相对=苹果触摸图标的href =图像/ touch.png/&GT;

&LT;链接相对=苹果触摸icon- precomposed的href =图像/ touch.png/&GT;


和下载图标,而无需关心的图标,你可以使用什么工具如 http://www.google.com/ S2 /网页图标将尽一切繁重的工作:

  VAR的客户=新System.Net.WebClient();

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

希望帮助!

Simple enough question: I've create 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. Look for the favicon.ico at the root of the domain

    www.domain.com/favicon.ico

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

    <link rel="shortcut icon" href="/favicon.ico" />

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

    <link rel="icon" href="/favicon.png" />

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


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_url=stackoverflow.com",
    "stackoverflow.com.ico");

Hope that helps!

这篇关于我怎样才能得到一个网站的图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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