0

我已经在本地驱动器上抓取并存储了页面 HTML。我现在需要使用 Python Newspaper(Ver 0.1.2)和 Python(Ver 2.7.10)提取内容、标题、图像等信息。我无法在 Internet 上找到与此相关的任何内容。我如何实现上述目标?

4

1 回答 1

1

您可能已经解决了这个问题。但这里有一种使用Newspaper解析存储的 HTML 文件的方法。

from newspaper import Article

article = Article('')
article.set_html(open("cnn_article.html").read())
article.parse()
title = article.title
authors = article.authors
text = article.text
keywords = article.meta_keywords
published_date = sorted({value for (key, value) in 
article.meta_data.items() if key == 'pubdate'})
于 2020-10-01T22:20:16.387 回答