Get Favicon - convert to PNG via Google
Get the favicon of a site, and automatically save it using one of Google's undisclosed services.
1. import urllib , re
2.
3. class favicon:
4.
5. def __init__ (self):
6. self.url = ''
7. self.favicon = ''
8. self.img = ''
9.
10. def domain(self, url):
11. items = re.compile('^http:\/\/.+$', re.I).findall(url)
12. if ( len(items) > 0 ):
13. items = re.compile('^http:\/\/', re.I).sub('', items[0])
14. print items
15. self.url = items
16. self._getFromGoogle()
17.
18. """
19. # WORKING ON THIS FUNCTION TO EXTRACT THE EXACT URL OF FAVICON
20. def _getFaviconLoc(self):
21. response = urllib.urlopen(self.url)
22. html = response.read()
23. items = re.compile('<head>(.+?)<\/head>' , re.S|re.I|re.M).findall(html)
24. if ( len(items) > 0 ):
25. getFavicon = re.compile('<link\s+.+?((?:href=[\'\"]*)(.+?)(?:[\'\"\s>]+)|>)').findall(items[0])
26. """
27.
28. def _getFromGoogle(self):
29. loc = 'http://www.google.com/s2/favicons?domain='+self.url
30. print loc
31. urllib.urlretrieve(loc, "test2.png")
32.
33.
34. a = favicon()
35. a.domain('http://www.google.com')
Comments