我正在尝试使用 GoogleNews API 检索新闻。当我搜索我的脚本时,经常会发生我没有找到任何文章的情况。如果我手动搜索,我经常会找到很多文章。我知道广告仅限于 30 天前的文章(至少在开发人员 News API 中)。
from newsapi import NewsApiClient
def find_articles(lst_of_keywords):
article_lst = [False] * 5
keywords = []
for keyword in lst_of_keywords:
if keyword:
keywords.append(keyword)
print(keywords)
api = NewsApiClient(api_key=API_KEY)
all_articles = api.get_everything(q=' '.join(keywords),
sort_by='publishedAt',
language='de')
print(all_articles)
print('Keywords:', ', '.join(keywords), '\n', 'Total results: ', str(all_articles['totalResults']), '\n')
num_article = 0
for article in all_articles['articles']:
print(article['title'] + ' - ' + article['source']['name'])
print(article['url'])
print(article['content'], '\n')
num_article += 1
if num_article == 5:
break
name = False
find_articles(["HOWOGE Wohnungsbaugesellschaft mbH Bau Wohnungen"])
我的结果:
['HOWOGE Wohnungsbaugesellschaft mbH Bau Wohnungen']
{'status': 'ok', 'totalResults': 0, 'articles': []}
Keywords: HOWOGE Wohnungsbaugesellschaft mbH Bau Wohnungen
Total results: 0
当我查看 news.google.com 时: