本文整理汇总了Python中newspaper.Article.title方法的典型用法代码示例。如果您正苦于以下问题:Python Article.title方法的具体用法?Python Article.title怎么用?Python Article.title使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类newspaper.Article
的用法示例。
在下文中一共展示了Article.title方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: home
# 需要导入模块: from newspaper import Article [as 别名]
# 或者: from newspaper.Article import title [as 别名]
def home(url):
data = {}
data['url'] = url
# Validate url
if urlparse.urlparse(url).scheme not in ('http', 'https'):
data['error'] = 'Invalid URL'
return json.dumps(data)
a = Article(url)
a.download()
a.parse()
data['title'] = a.title
data['authors'] = a.authors
data['text'] = a.text
try:
a.nlp()
except UnicodeDecodeError:
# Strip non-ascii characters
a.title = to_ascii(a.title)
a.text = to_ascii(a.text)
a.nlp()
# NLP
data['summary'] = a.summary
data['keywords'] = a.keywords
data['tags'] = list(a.tags)
# Media
data['top_image'] = a.top_image
data['images'] = a.images
data['movies'] = a.movies
# Meta
data['source_url'] = a.source_url
data['published_date'] = a.published_date
data['meta_img'] = a.meta_img
data['meta_keywords'] = a.meta_keywords
data['meta_lang'] = a.meta_lang
return json.dumps(data)