Skip to content

Commit cda2ef6

Browse files
author
Xavier Grangier
committed
grangier#142 - extract authors
1 parent 8a4ecf2 commit cda2ef6

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

goose/article.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ def __init__(self):
7474
# holds links found in the main article
7575
self.links = []
7676

77+
# hold author names
78+
self.authors = []
79+
7780
# stores the final URL that we're going to try
7881
# and fetch content against, this would be expanded if any
7982
self.final_url = u""

goose/crawler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def crawl(self, crawl_candidate):
105105
self.article.canonical_link = self.extractor.get_canonical_link()
106106
self.article.domain = self.extractor.get_domain()
107107
self.article.tags = self.extractor.extract_tags()
108+
self.article.authors = self.extractor.extract_authors()
108109

109110
# opengraph
110111
self.article.opengraph = self.extractor.extract_opengraph()

goose/extractors.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,25 @@ def extract_links(self):
259259
links.append(attr)
260260
return links
261261

262+
def extract_authors(self):
263+
authors = []
264+
author_nodes = self.parser.getElementsByTag(
265+
self.article.doc,
266+
attr='itemprop',
267+
value='author')
268+
269+
for author in author_nodes:
270+
name_nodes = self.parser.getElementsByTag(
271+
author,
272+
attr='itemprop',
273+
value='name')
274+
275+
if len(name_nodes) > 0:
276+
name = self.parser.getText(name_nodes[0])
277+
authors.append(name)
278+
279+
return list(set(authors))
280+
262281
def extract_tags(self):
263282
node = self.article.doc
264283

0 commit comments

Comments
 (0)