瀏覽代碼

Work around buggy HTML Parser in Python < 2.7.3 (Closes #662)

Philipp Hagemeister 12 年之前
父節點
當前提交
3b024e17af
共有 1 個文件被更改,包括 6 次插入0 次删除
  1. 6 0
      youtube_dl/utils.py

+ 6 - 0
youtube_dl/utils.py

@@ -280,6 +280,12 @@ class AttrParser(compat_html_parser.HTMLParser):
             lines[-1] = lines[-1][:self.result[2][1]-self.result[1][1]]
         lines[-1] = lines[-1][:self.result[2][1]]
         return '\n'.join(lines).strip()
+# Hack for https://github.com/rg3/youtube-dl/issues/662
+if sys.version_info < (2, 7, 3):
+    AttrParser.parse_endtag = (lambda self, i:
+        i + len("</scr'+'ipt>")
+        if self.rawdata[i:].startswith("</scr'+'ipt>")
+        else compat_html_parser.HTMLParser.parse_endtag(self, i))
 
 def get_element_by_id(id, html):
     """Return the content of the tag with the specified ID in the passed HTML document"""