How can I get favicon website?

A fairly simple question: I created a small application, which is basically a favorite that sits in my system tray, so that I can open frequently used sites / folders / files from the same place. Getting the default icons from my system for known file types is not very difficult, but I don’t know how to get the icon from the website. (SO has a gray-> orange stack icon in the address bar, for example)

Does anyone know how I can do this?

+85
c # favicon
Feb 25 2018-11-11T00:
source share
13 answers

You need to solve several ways:

  • Find favicon.ico in the root of the domain

    www.domain.com/favicon.ico

  • Find the <link> with the attribute rel="shortcut icon"

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

  • Look for the <link> with the attribute rel="icon"

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

The last two usually give a higher quality image.




Just to cover all databases, there are files with specific devices that can give better images, since these devices usually have larger icons on the device than the browser:

<link rel="apple-touch-icon" href="images/touch.png" />

<link rel="apple-touch-icon-precomposed" href="images/touch.png" />




And to download an icon without worrying about which icon you can use, for example, http://www.google.com/s2/favicons , which will do all the hard work

 var client = new System.Net.WebClient(); client.DownloadFile( @"http://www.google.com/s2/favicons?domain=stackoverflow.com", "stackoverflow.com.ico"); 

Hope this helps!

+184
Feb 25 '11 at 15:30
source share

Here are 2 options, I checked over 100 URLs and got different results, which are each option. Note that this solution is not C #, but C # may not be needed.

 <img height="16" width="16" src='http://grabicon.com/edocuments.co.uk' /> <img height="16" width="16" src='http://www.google.com/s2/favicons?domain=www.edocuments.co.uk' /> 
+11
May 29 '12 at 9:08 a.m.
source share
+8
Feb 19 '14 at 1:24
source share

The first thing to look for is /favicon.ico at the root of the site; something like WebClient.DownloadFile () should succeed. However, you can also set the icon in the metadata - for SO, this is:

 <link rel="shortcut icon" href="http://sstatic.net/stackoverflow/img/favicon.ico"> 

and note that alternative icons are available; for example, “touch” is usually larger and higher than res, for example:

 <link rel="apple-touch-icon" href="http://sstatic.net/stackoverflow/img/apple-touch-icon.png"> 

so that you analyze this in both the HTML Agility Pack and the XmlDocument (if xhtml) and use WebClient.DownloadFile ()

Here is the code I used to get this through the flexibility package:

 var favicon = "/favicon.ico"; var el=root.SelectSingleNode("/html/head/link[@rel='shortcut icon' and @href]"); if (el != null) favicon = el.Attributes["href"].Value; 

Please note that the icon belongs to them, not yours.

+6
Feb 25 2018-11-15T00:
source share

It is good practice to minimize the number of requests each page needs. Therefore, if you need several icons, yandex can make sprite favicons in one request. Here is an example http://favicon.yandex.net/favicon/google.com/stackoverflow.com/yandex.net/

+4
Feb 11 '16 at 0:51
source share

Yo can get favicon url from website html.

Here is the favicon tag:

 <link rel="icon" type="image/png" href="/someimage.png" /> 

You should use regex here. If the tag is not found, find "favicon.ico" in the root directory of the site. If nothing is found, there is no icon on the site.

+3
Feb 25 '11 at 15:33
source share
  HttpWebRequest w = (HttpWebRequest)HttpWebRequest.Create("http://stackoverflow.com/favicon.ico"); w.AllowAutoRedirect = true; HttpWebResponse r = (HttpWebResponse)w.GetResponse(); System.Drawing.Image ico; using (Stream s = r.GetResponseStream()) { ico = System.Drawing.Image.FromStream(s); } ico.Save("favicon.ico"); 
+2
Feb 25 '11 at 3:40
source share

You can do this without programming . Just open a website, right-click and select "source" to open the HTML code for this website. Then in the text editor, find the “icon” - it will direct you to something similar to

 <link rel="icon" href='/SOMERELATIVEPATH/favicon.ico' type="image/x-icon" /> 

take the line in href and add it to the base URL of the website (let's say it's "http://WEBSITE/" ), so it looks like

http://WEBSITE/SOMERELATIVEPATH/favicon.ico

which is the absolute path to the sign. If you did not find it this way, it could be at the root, in this case the URL is http://WEBSITE/favicon.ico .

Take the URL you provided and paste it into the following code:

 <html> <head> <title>Capture Favicon</title> </head> <body> <a href='http://WEBSITE/SOMERELATIVEPATH/favicon.ico' alt="Favicon"/>Favicon</a> </body> </html> 

Save this HTML code locally (e.g. on your desktop) as GetFavicon.html , and then double-click it to open it. It will only display a link named Favicon . Right-click on this link and select "Save Target As ..." to save the favicon to your local PC - and you're done!

+2
Jul 02 '13 at 14:48
source share

This is a late answer, but for completeness: it’s quite difficult to get even about 90% of the sample of all the icons.

Some time ago I wrote a WordPress plugin: http://wordpress.org/extend/plugins/wp-favicons/ , which is trying to get closer.

but. it starts by browsing favicon repositories like google favicons, getfavicons etc.

b. if none of them returns an icon (I check this by matching the default icon that they return) I start by trying to get the icon myself

from. this includes moving pages, but also checking redirects with NO autoredirect, as well as moving 404, because the icon may also be present on 404. In the end, this means that you will have to parse the redirects in the html header as well as the javascript redirects to get close to 100%

e. after that I do some checks in the physical image file, because sometimes on some servers (I tested 300,000+) sometimes the files are returned with the wrong mime type, etc.

The code is still not perfect, because it goes crazy in the details, you will find many strange situations: people have erroneously encoded paths (img / favicon.ico, where img is NOT in the root), duplicate headers in the html output, various server responses from head and body, etc.

the core of the resulting part is here: http://plugins.svn.wordpress.org/wp-favicons/trunk/includes/server/class-http.php so you can deploy it, but remember that checking the answer should really be (check image file, mime, etc.)

+1
Feb 24 '13 at 17:54
source share

I found that “SHGetFileInfo” (check “www.pinvoke.net” for signature) allows you to get a small or large icon, just as if you were dealing with a file / folder / shell element.

Jens;)

+1
Nov 12 '13 at 17:53
source share

You can use Getfv.co :

To get the badge, you can link it ... http://g.etfv.co/[URL]

Example for this page: stack overflow

Download content and release!

Edit:

Getfv.co and fvicon.com look dead. If you want, I found some free alternative: grabicon.com .

0
Aug 01 '13 at 23:19
source share

/qaru.site / ... gives you favicon analysis indicating which icons are present in what size. You can process the page information to find out what is the best quality badge, and add its file name in the URL to get it.

0
Sep 11 '15 at 8:59
source share

Using jquery

 var favicon = $("link[rel='shortcut icon']").attr("href") || $("link[rel='icon']").attr("href") || ""; 
0
May 11 '19 at 22:00
source share



All Articles