I am trying to get a list of the top business/technology headlines using NewsApi in Python using this function:
def get_customized_news(phrase, n_news=15,pageAmount=30):
articles = newsapi.get_top_headlines(q=phrase,
language="en",
page_size = n_news,
page=pageAmount,
sources=NewsApiClient.get_sources(category='business,technology',language='en'))
print(articles['articles'])
However when doing so I would mostly get null results after typing simple phrases such as "Blackrock" or "Apple stock" and when replacing top headlines with the get_everything function I simply just get irrelevant results despite specifying the domains I want to use. How would I be able to get relevant, top headlines from pythons newsapi?
So it looks like the main problem you're having is with this line:
sources=NewsApiClient.get_sources(category='business,technology',language='en'))self(needs to be called as an instance method)sourcesparameter needs to be a comma delimited list of only the source ids; for examplesources="bbc-news,wired"I ran the following with success: