我最近一直在使用报纸图书馆。我发现的唯一问题是当我这样做时,article.publish_date
我总是得到None
.
class NewsArticle:
def __init__(self,url):
self.article = Article(url)
self.article.download()
self.article.parse()
self.article.nlp()
def getKeywords(self):
x = self.article.keywords
for i in range(0,len(x)):
x[i] = x[i].encode('ascii', 'ignore')
return x
return self.article.keywords
def getSummary(self):
return self.article.summary.encode('ascii', 'ignore')
def getAuthors(self):
x = self.article.authors
for i in range(0,len(x)):
x[i] = x[i].encode('ascii', 'ignore')
return x
def thumbnail_url(self):
return self.article.top_image.encode('ascii', 'ignore')
def date_made(self):
print self.article.publish_date
return self.article.publish_date
def get_videos(self):
x=self.article.movies
for i in range(0,len(x)):
x[i] = x[i].encode('ascii', 'ignore')
return x
def get_title(self):
return self.article.title.encode('ascii','ignore')
我正在浏览一堆 URL。你可以看到我publish_date
在返回之前打印出来。
正如我之前所说:
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
所有其他功能都按预期工作。该站点的文档查看了一个示例,
>>> article.publish_date
datetime.datetime(2013, 12, 30 0, 0)
我正在这样做,我很确定。我不确定是否有人注意到我的问题。