gefavic/gefavic/getfavicon.py

23 lines
706 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from html.parser import HTMLParser
class favfinder(HTMLParser):
attrs = []
def handle_starttag(self, tag, attrs):
if tag == 'link':
for attr in attrs:
if 'rel' in attr and attr[1].find('icon') > 0:
self.attrs = attrs
def gethtml(url):
return "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><link rel=\"stylesheet\" type=\"text/css\" href=\"../static/style.css\"><link rel=\"shortcut icon\" type=\"image/png\" href=\"../static/py.png\"></head><body></body></html>"
def main(options):
ff = favfinder()
response = gethtml(options.url)
ff.feed(response)
print(ff.attrs)