瀏覽代碼

ignore parsing errors in get_element_by_id()

Filippo Valsorda 13 年之前
父節點
當前提交
7a8501e307
共有 2 個文件被更改,包括 8 次插入2 次删除
  1. 4 1
      youtube-dl
  2. 4 1
      youtube_dl/__init__.py

+ 4 - 1
youtube-dl

@@ -252,7 +252,10 @@ class IDParser(HTMLParser.HTMLParser):
 def get_element_by_id(id, html):
 	"""Return the content of the tag with the specified id in the passed HTML document"""
 	parser = IDParser(id)
-	parser.loads(html)
+	try:
+		parser.loads(html)
+	except HTMLParser.HTMLParseError:
+		pass
 	return parser.get_result()
 
 

+ 4 - 1
youtube_dl/__init__.py

@@ -252,7 +252,10 @@ class IDParser(HTMLParser.HTMLParser):
 def get_element_by_id(id, html):
 	"""Return the content of the tag with the specified id in the passed HTML document"""
 	parser = IDParser(id)
-	parser.loads(html)
+	try:
+		parser.loads(html)
+	except HTMLParser.HTMLParseError:
+		pass
 	return parser.get_result()