Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix title cleaning #195

Closed
wants to merge 3 commits into from
Closed
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
25 changes: 4 additions & 21 deletions goose/extractors/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
from goose.extractors import BaseExtractor


TITLE_SPLITTERS = [u"|", u"-", u"»", u":"]


class TitleExtractor(BaseExtractor):

def clean_title(self, title):
Expand All @@ -46,24 +43,10 @@ def clean_title(self, title):
pattern = re.compile(self.article.domain, re.IGNORECASE)
title = pattern.sub("", title).strip()

# split the title in words
# TechCrunch | my wonderfull article
# my wonderfull article | TechCrunch
title_words = title.split()

# check if first letter is in TITLE_SPLITTERS
# if so remove it
if title_words[0] in TITLE_SPLITTERS:
title_words.pop(0)

# check if last letter is in TITLE_SPLITTERS
# if so remove it
if title_words[-1] in TITLE_SPLITTERS:
title_words.pop(-1)

# rebuild the title
title = u" ".join(title_words).strip()

# Remove Title splitters
title_words = re.split('\|| |:|»|-', title)
title_words = [w.strip() for w in title_words if w != '']
title = u" ".join(w for w in title_words).strip()
return title

def get_title(self):
Expand Down