How can I get a web site's favicon?

前端 未结 14 2166
旧巷少年郎
旧巷少年郎 2020-12-22 15:28

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

14条回答
  •  醉话见心
    2020-12-22 16:03

    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 tag with the rel="shortcut icon" attribute

    3. Look for a 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:


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

提交回复
热议问题