Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions newspaper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
popular_urls, NewsPool, Configuration as Config)
from .source import Source
from .version import __version__
from .extractors import ContentExtractor
from .parsers import Parser
from .network import get_html

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why add imports here?


news_pool = NewsPool()

Expand Down
8 changes: 6 additions & 2 deletions newspaper/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ class ArticleException(Exception):
class Article(object):
"""Article objects abstract an online news article page
"""
def __init__(self, url, title='', source_url='', config=None, **kwargs):
def __init__(self, url, title='', source_url='', config=None, content_extractor=None, **kwargs):
"""The **kwargs argument may be filled with config values, which
is added into the config object
"""
self.config = config or Configuration()
self.config = extend_config(self.config, kwargs)

self.extractor = ContentExtractor(self.config)
if content_extractor is None:
self.extractor = ContentExtractor(self.config)
else:
self.extractor = content_extractor

if source_url == '':
source_url = urls.get_scheme(url) + '://' + urls.get_domain(url)
Expand Down Expand Up @@ -212,6 +215,7 @@ def parse(self):

text = ''
self.top_node = self.extractor.calculate_best_node(self.doc)
#self.top_node = document_cleaner.clean(self.top_node)
if self.top_node is not None:
video_extractor = VideoExtractor(self.config, self.top_node)
self.set_movies(video_extractor.get_videos())
Expand Down
2 changes: 1 addition & 1 deletion newspaper/cleaners.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def clean(self, doc_to_clean):
self.facebook_braodcasting_re)
doc_to_clean = self.remove_nodes_regex(doc_to_clean, self.twitter_re)
doc_to_clean = self.clean_para_spans(doc_to_clean)
doc_to_clean = self.div_to_para(doc_to_clean, 'div')
#doc_to_clean = self.div_to_para(doc_to_clean, 'div')
doc_to_clean = self.div_to_para(doc_to_clean, 'span')
return doc_to_clean

Expand Down
1 change: 1 addition & 0 deletions newspaper/outputformatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get_formatted(self, top_node):
self.remove_trailing_media_div()
text = self.convert_to_text()
# print(self.parser.nodeToString(self.get_top_node()))
#print(text)
return (text, html)

def convert_to_text(self):
Expand Down