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
11 changes: 10 additions & 1 deletion newspaper/outputformatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
__copyright__ = 'Copyright 2014, Lucas Ou-Yang'

from HTMLParser import HTMLParser
import logging

from .text import innerTrim


log = logging.getLogger(__name__)


class OutputFormatter(object):

def __init__(self, config):
Expand Down Expand Up @@ -60,7 +64,12 @@ def get_formatted(self, top_node):
def convert_to_text(self):
txts = []
for node in list(self.get_top_node()):
txt = self.parser.getText(node)
try:
txt = self.parser.getText(node)
except ValueError: # lxml error

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should at least print out warnings + fail loudly if this happens. Maybe notify the url that failed so the developer can triage further? The ideal is to debug urls that don't work so the library can slowly extract more successfully.

log.warning('Error parsing lxml node', exc_info=True)
txt = None

if txt:
txt = HTMLParser().unescape(txt)
txt_lis = innerTrim(txt).split(r'\n')
Expand Down