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 extraction if title is same as site_name #197

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions goose/extractors/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def clean_title(self, title):
# my wonderfull article | TechCrunch
title_words = title.split()

if not title_words:
return str()

# check if first letter is in TITLE_SPLITTERS
# if so remove it
if title_words[0] in TITLE_SPLITTERS:
Expand Down
14 changes: 14 additions & 0 deletions tests/data/extractors/title/test_title_opengraph_empty.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
<meta property="og:site_name" content="TechCrunch"/>
<meta property="og:title" content="TechCrunch"/>
<title>Wrong article title - website</title>
</head>
<body>
<div>
<p>
TextNode 1 - The Scala supported IDE is one of the few pain points of developers who want to start using Scala in their Java project. On existing long term project developed by a team its hard to step in and introduce a new language that is not supported by the existing IDE. On way to go about it is to hid the fact that you use Scala from the Java world by using one way dependency injection. Still, if you wish to truly absorb Scala into your existing java environment then you'll soon introduced cross language dependencies.
</p>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions tests/data/extractors/title/test_title_opengraph_empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"url": "http://exemple.com/test_opengraphcontent",
"expected": {
"title": ""
}
}
5 changes: 5 additions & 0 deletions tests/extractors/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ def test_title_opengraph(self):
article = self.getArticle()
fields = ['title']
self.runArticleAssertions(article=article, fields=fields)

def test_title_opengraph_empty(self):
article = self.getArticle()
fields = ['title']
self.runArticleAssertions(article=article, fields=fields)