Yes, there is even a library for downloading favicon. This one is called pyfav (GitHub), it will try to find out the location of favicon associated to a given URL. Here is a quick example:
Python 2.7.5 (default, Mar 29 2014, 07:05:13) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from pyfav import download_favicon >>> favicon_saved_at = download_favicon('https://www.python.org/') >>> favicon_saved_at '/tmp/favicon.ico' >>> favicon_saved_at = download_favicon('https://www.python.org/', \ ... file_prefix='python.org-', target_dir='/tmp/favicon-downloads') >>> favicon_saved_at '/tmp/favicon-downloads/python.org-favicon.ico' >>> from pyfav import get_favicon_url >>> favicon_url = get_favicon_url('https://www.python.org/') >>> favicon_url 'https://www.python.org/static/favicon.ico'
By default, the icon is downloaded at /tmp, but you can change to wherever you like to save the favicon, you can also prefix string to the filename. If you don’t want the library to download for you, you could simply get a URL of the icon and do whatever you like with that.
It doesn’t have command-line interface, which it should in my opinion. It would be more helpful with that, without needing to wrap up a Python script, when you want to download using a shell script, if someone intends to use that way.
pyfav is written by Matthew Phillips for Python 2, under the MIT License, currently version 0.1 (2014-04-06).
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.