from newspaper import build
articles = []
urls_set = set()
cnn_articles = build('http://cnn.com', memoize_articles=False)
for article in cnn_articles.articles:
# check to see if the article url is not within the urls_set
if article.url not in urls_set:
# add the unique article url to the set
urls_set.add(article.url)
articles.append(article.url)
print(len(articles))
# 698
报纸仅查询CNN主页上的项目,因此该模块不会查询域上的所有类别(如业务、健康等)。根据我的代码,到今天为止,报纸只发现了698篇独特的文章。这些文章中的一些可能是相同的,因为有些URL有哈希,但看起来是同一篇文章
另外,您可以查询所有类别,但这需要硒与报纸相结合
相关问题 更多 >
编程相关推荐