How to get the favicon.ico from any Page

Recently, I was in the need of retrieving the favicon.ico file from a website. As I had to process the file programmatically and render it on a website, it would have been quite a lot of manual work to get the .ico file and make sure the browser does render it in the correct way. After digging around, I learned about a secret URI probably provided once by Google’s social bookmarking service Google Shared Stuff. While Google Shared Stuff was launched in 2007,  it was already discontinued in 2009. However, this one URI seems to work perfectly maybe because it is still used within Google extensively.

The Secret

To get the favicon.ico file from any arbitrary page you simply have to use an URI using the following pattern:

http://www.google.com/s2/favicons?domain=www.example.org

Eventually, this URI will provide you the following image: Image retrieved using http://www.google.com/s2/favicons?domain=www.example.org

How it Works

Some More examples to see how it works:

  • Facebook
  • TechChrunch
  • aheil blog
  • Google
  • dotnetpro Magazine
  • heise.de
  • Google+

As most of the sites do keep their favicon.ico file right in the root of the web site, others like Google don’t. Actually, you might find Google’s plus icon located at

https://ssl.gstatic.com/s2/oz/images/faviconr2.ico

While this is probably not a problem retrieving the favicon.ico file using the standard URI at all, the secret URI provides one major advantage: you’ll get the icon as a nice 16×16 PNG file, ready to be rendered in any <img> tag right away.

The Risk

As every time building up on a Google service as I did before, it might disappear tomorrow without notice leaving your site with quite a bunch of 404s though. Even worse, as it seems there is no official support for this URI, there won’t be any notice or deprecation period until switched of as done for other services like Feedburner.

13 Comments

  1. essej

    Reply

    How do I get the returned image into a dll or exe file so that I can associate it with a favorite using IE8?

  2. Reply

    You’re right, this is not a supported service from google.

    http://grabicon.com is a drop-in replacement for google’s favicon service. It’s free, lets you specify the icon size you want, and even generates a unique default icon for sites that don’t have one.

    Grabicon is also growing, so we’ll be around for a long time!

  3. Reply

    Hey Man,
    thanks for sharing this. Do you know how to get bigger size of the favicon? Currently the size Google shows is less than 10pixel.

    It would be also cool if you know any solution which can scrap the home page screenshot for 100URL in bulk.

    Thanks Man!

    • andreas

      Reply

      The icon shown (favicon) is usually 16×16 pixels. For most sites, this is probably exactly the size the icon is saved on the server. It heavily depends on the server, if the website uses a .ico file there might be a chance that there are 16×16, 32×32 and 48×48 versions of the image in the .ico file.

      As mentioned in a comment above, you might want to try the DuckDuckGo service similar to the Google service. For this blog it is https://icons.duckduckgo.com/ip2/aheil.de.ico and it will give you the .ico file with a higher resolution,

      In terms of capturing homepages I know https://snapito.com/, it is free AFAIK and it provides some kind URLs to pick a screenshot. You have to work out some script to get it down as bulk. Maybe there is some patter, API based service out there, however, I am not aware of anything.

Leave Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.