How to get favicons website?

I am using Ruby on Rails v3.0.9, and I would like to get the favicon.ico image of each website for which I have set the link.

That is, if I set the URL http://www.facebook.com/ in my application, I would like to get the Facebook icon and use \ paste it on my web pages. Of course, I would like to do this for all other websites.

How can I get favicon.ico badges from websites "automatically" (with "automatic" I mean looking for an icon on a website and getting a link to it - I think not, because not all websites have websites is there an icon named “favicon.ico.” I would like to admit that this is an “automatic” way)?

PS: What I would like to do is something like Facebook, when I need to add the link \ URL on your Facebook page: it recognizes the corresponding website logo and adds it to the link \ URL.

+6
source share
7 answers

With javascript (jQuery), for example: http://jsfiddle.net/aX8T4/

0
source

http://getfavicon.appspot.com/ great for picking icons. Just give it the url for the site and you will return the icon:

http://g.etfv.co/http://www.google.com

+3
source

Icons found in two ways. First, there is a "hard-coded", traditional name "http://example.com/favicon.ico".

Secondly, HTML pages can define an icon in their sections <head> , <link rel="icon"...> and several others. (You can read the Wikipedia article on the icon )

So, your machine can get the main page of this website, analyze it and check if <link> tags exist, and then, as a backup, try the "hard-coded" favicon.ico name.

+1
source

I think I missed your question ...

Do you want to grab an icon from another site and make it yours?

if this is what you want, you can get it directly from the house icon and save it in your shared folder.

this way: www.facebook.com favicon: www.facebook.com/favicon.ico

take this image and save it as favicon in your shared folder

do it should be enough


if you want this to be dynamic, you can use jquery, but if you want static text, you can put an image tag pointing to: [root URL of website] /favicon.ico

like this: <%= image_tag "#{website.url}/favicon.ico" %>

0
source

Can't you use a regular img tag with an src attribute pointing to an icon?

 <img src="http://www.facebook.com/favicon.icon"> 

It is assumed that the browser recognizes the .ico file as an image. The methods would help, probably, they would also work with this.

0
source

You can do this easily with pismo gem.

A quick example to get the Facebook favicon url:

 Pismo::Document.new('http://www.facebook.com/').favicon 
0
source

Here's my ruby ​​method, which will remove the end of the url, add an icon and create an image tag.

  def favicon_for(url) matches = url.match(/[^:\/]\/(.*)/) image_tag url.sub(matches[1], '') + '/favicon.ico', {width: '16px', height: '16px'} end 
0
source

Source: https://habr.com/ru/post/895872/


All Articles