Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions newspaper/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lxml.etree
import lxml.html
import lxml.html.clean
import re

from copy import deepcopy

Expand Down Expand Up @@ -43,6 +44,10 @@ def css_select(cls, node, selector):
def fromstring(cls, html):
html = utils.encodeValue(html)
try:
# Remove encoding tag because lxml won't accept it for unicode objects (Issue #78)
if html.startswith('<?'):
html = re.sub(r'^\<\?.*?\?\>', '', html, flags=re.DOTALL)

cls.doc = lxml.html.fromstring(html)
except Exception, e:
print '[Parse lxml ERR]', str(e)
Expand Down