Skip to content
Open
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
6 changes: 6 additions & 0 deletions newspaper/cleaners.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def __init__(self, config):
"|date|^print$|popup|author-dropdown|tools|socialtools|byline"
"|konafilter|KonaFilter|breadcrumbs|^fn$|wp-caption-text"
"|legende|ajoutVideo|timestamp|js_replies"
"|date|^print$|popup|author-dropdown|tools|socialtools|byline"
"|konafilter|KonaFilter|breadcrumbs|^fn$|wp-caption-text"
"|legende|ajoutVideo|timestamp|js_replies|breadcrumb|^rating$""|^comment$|^share$|^like$|^icon$|^count$|^sharing$|^news-list$"
"|^vote$|^ad$|^Ad$|^rec$|^oneindia$|^inread$|^showmore$|^tags_scroll$""|^Share$|^date$|^related$|^fb-root$|^recommendation$|^recomment$"
"|^readalso$|^read-also$|^image_counter$|^yarp$|^navig$|^extranews$""|^arrow$|^slider__footer$|^socbuttons$|^see-more$|^subscribe$"
"|post-data|post-social|article__content__author-title|archive__posts__item""|user|^banner$|^flair$|^forlo$|append-news|^inject$|^rg-gallery_inj$|^tag$"
)
self.regexp_namespace = "http://exslt.org/regular-expressions"
self.nauthy_ids_re = ("//*[re:test(@id, '%s', 'i')]" %
Expand Down
9 changes: 8 additions & 1 deletion newspaper/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import re
from collections import defaultdict

from difflib import SequenceMatcher
from dateutil.parser import parse as date_parser
from tldextract import tldextract
from urllib.parse import urljoin, urlparse, urlunparse
Expand Down Expand Up @@ -342,11 +343,17 @@ def get_title(self, doc):
# (either it differs for case, for special chars, or it's truncated)
# in these cases, we prefer the title_text_h1
filter_title = filter_regex.sub('', title).lower()
if filter_title_text_h1 == filter_title:
if self.is_similar(filter_title_text_h1, filter_title):
title = title_text_h1

return title

def is_similar(self, text_a, text_b):
"""used for comparison between the final title and title_text_h1
0.6 is an empirical value
"""
return SequenceMatcher(None, text_a, text_b).ratio() > 0.6

def split_title(self, title, splitter, hint=None):
"""Split the title to best part possible
"""
Expand Down