-Parse <meta charset="...">
-
-
Switch simple robot to urllib2.
A new robot based on PycURL.
"""
__author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2007-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2007-2013 PhiloSoft Design"
__license__ = "GNU GPL"
__all__ = ['parse_html']
else:
meta_charset = False
+ if not meta_charset:
+ meta = head.find(_find_charset, recursive=False)
+ if meta:
+ meta_content = meta.get("charset")
+ if meta_content:
+ meta_charset = _charset = meta_content.lower()
+
if title and (_charset or meta_charset):
title = title.encode(_charset or meta_charset)
return (Tag.name == "meta") and \
(Tag.get("http-equiv", '').lower() == "content-type")
+def _find_charset(Tag):
+ return (Tag.name == "meta") and Tag.get("charset", '')
+
def _find_refresh(Tag):
return (Tag.name == "meta") and \
(Tag.get("http-equiv", '').lower() == "refresh")
"""
__author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2010-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2010-2013 PhiloSoft Design"
__license__ = "GNU GPL"
__all__ = ['parse_html']
break
except IndexError:
meta_charset = False
+ elif m.get('charset', ''):
+ meta_charset = m.get('charset').lower()
+ break
else:
meta_charset = False
"""
__author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2010-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2010-2013 PhiloSoft Design"
__license__ = "GNU GPL"
__all__ = ['parse_html']
title = ''
for node in head.childNodes:
- if node.name == 'meta' and \
+ if (node.name == 'meta') and \
('http-equiv' in node.attributes) and \
(node.attributes['http-equiv'] == 'content-type'):
meta_content = node.attributes['content']
meta_charset = False
else:
break
+ elif (node.name == 'meta') and ('charset' in node.attributes):
+ meta_charset = node.attributes['charset'].lower()
+ break
if not charset:
charset = parser.tokenizer.stream.charEncoding[0]
"""
__author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 1997-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 1997-2013 PhiloSoft Design"
__license__ = "GNU GPL"
__all__ = ['parse_html']
http_equiv = value.lower()
elif attrname == 'content':
content = value
+ elif (attrname == 'charset') and (not self.charset):
+ self.charset = value.lower()
+ self.meta_charset = 1
if (not self.charset) and (http_equiv == "content-type"):
try:
"""
__author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2010-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2010-2013 PhiloSoft Design"
__license__ = "GNU GPL"
__all__ = ['parse_html']
break
except IndexError:
meta_charset = False
+ elif m.get('charset', ''):
+ meta_charset = m.get('charset').lower()
+ break
else:
meta_charset = False