How can I get a web site's favicon?

前端 未结 14 2169
旧巷少年郎
旧巷少年郎 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:02

    This is a late answer, but for completeness: it is difficult to get even close to fetching 90% all favicons.

    A while ago I wrote a WordPress plugin which attempts to get closer to 100%.

    This is how it works:

    1. It starts by searching existing favicon repositories such as Google favicons and GetFavicons for the favicon.

    2. If none of them returns an icon, the plugin attempts to get the icon itself. This involves traversing several pages on the domain.

    3. The plugin then inspects the physical image file, because on some servers files get returned with the incorrect mime types.

    The code is still not perfect because in the details you will find many weird situations: people have wrongly coded paths, e.g. img/favicon.ico where img is not in the root, duplicate headers in HTML output, different server responses from the head and body etc.

    The core of the fetching part is here so you can reverse-engineer it, but be aware that validating the response should be done (checking image filetype, mime etc.).

提交回复
热议问题