-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom_article.py
25 lines (22 loc) · 1 KB
/
custom_article.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from breadability.readable import Article, leaf_div_elements_into_paragraphs
from breadability.utils import cached_property
from lxml.html.clean import Cleaner
html_cleaner = Cleaner(
scripts=True, javascript=True, comments=True,
style=True, links=True, meta=False, add_nofollow=False,
page_structure=False, processing_instructions=True,
embedded=False, frames=False, forms=False,
annoying_tags=False, remove_tags=None, kill_tags=("noscript", "iframe", "figcaption"),
remove_unknown_tags=False, safe_attrs_only=False)
class CustomArticle(Article):
''' Customized Article that avoids certain tags '''
@cached_property
def dom(self):
"""Parsed lxml tree (Document Object Model) of the given html."""
try:
dom = self._original_document.dom
# cleaning doesn't return, just wipes in place
html_cleaner(dom)
return leaf_div_elements_into_paragraphs(dom)
except ValueError:
return None