4

I need to get web site's favicon.

How can I do that?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
vmg
  • 9,920
  • 13
  • 61
  • 90

3 Answers3

2

Here is a bit crazy but working solution:

Needle is a tool for testing your CSS with Selenium and nose.

It checks that CSS renders correctly by taking screenshots of portions of a website and comparing them against known good screenshots. It also provides tools for testing calculated CSS values and the position of HTML elements.

In other words, we are going to compare favicon images.

Example implementation (python):

from needle.cases import NeedleTestCase

class FavIconTestCase(NeedleTestCase):
    def test_so(self):
        self.driver.get('http://www.google.com/s2/favicons?domain=www.stackoverflow.com')
        self.assertScreenshot('img', 'so-favicon')
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
2

You won't be able to get the favicon with Selenium you would have to use another program to grab it. The only way you would be able to get it is if your website rendered the favicon.ico as a link such as

<link rel="shortcut icon"
 href="http://example.com/myicon.ico" />

However typically websites just store the favicon.ico in the root directory and on page request the browser retrieves it and drops it in the address bar or tab or wherever favicons are used. If this is how your favicon is rendered then there will be no code or anything to search for with Selenium.

Also the above code while it does work has some buggy support for IE7.

CBRRacer
  • 4,649
  • 1
  • 23
  • 27
1

You don't need Selenium.

Just request the site's home page and use an HTML parser to find a <link rel="shortcut icon" href="..."> tag.

If you don't find any such tag, try /favicon.ico.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 3
    he's probably wondering how to get it for testing purposes to verify that the favicon is the correct one and not a generic one. – CBRRacer Dec 15 '11 at 19:26