self.parsing = False
self.subs = []
self.attr = None
+ self.cur = None
+ self.in_script_style = False
def handle_starttag(self, tag, attrs):
attrs = dict(attrs)
self.parsing = True
if not self.parsing:
return
+ if tag == 'script' or tag == 'style':
+ self.in_script_style = True
+ return
if tag == 'div':
if attrs.get('id') == 'buscador_detalle':
self.parsing = True
def handle_endtag(self, tag):
if self.parsing:
+ if tag == 'script' or tag == 'style':
+ self.in_script_style = False
+ return
self.depth -= 1
if self.depth == 0:
self.parsing = False
def handle_data(self, data):
- if self.parsing:
- data = data.strip()
- if self.attr is not None and data:
- self.cur[self.attr] = data
- self.attr = None
- elif data in ('Downloads:', 'Cds:', 'Comentarios:',
- 'Formato:'):
- self.attr = data[:-1].lower()
- elif data == 'Subido por:':
- self.attr = 'autor'
- elif data == 'el':
- self.attr = 'fecha'
+ if not self.parsing:
+ return
+ data = data.strip()
+ # Hack to handle comments in <script> <style> which don't end
+ # up in handle_comment(), so we just ignore the whole tags
+ if self.in_script_style:
+ return
+ if self.attr is not None and data:
+ self.cur[self.attr] = data
+ self.attr = None
+ elif data in ('Downloads:', 'Cds:', 'Comentarios:',
+ 'Formato:'):
+ self.attr = data[:-1].lower()
+ elif data == 'Subido por:':
+ self.attr = 'autor'
+ elif data == 'el':
+ self.attr = 'fecha'
def subdivx_get_subs(query_str):