base_url = "https://api.newscatcherapi.com/v2/search"
X_API_KEY = 'PUT_YOUR_API_KEY'
# Define your desired parameters
# Put your API key to headers in order to be authorized to perform a call
headers = {"x-api-key": X_API_KEY}
# Variable to store all found news articles
# Ensure that we start from page 1
# Infinite loop which ends when all articles are extracted
# Wait for 1 second between each call
response = requests.get(base_url, headers=headers, params=params)
results = json.loads(response.text.encode())
if response.status_code == 200:
print(f'Done for page number => {params["page"]}/{results["total_pages"]}')
# Storing all found articles
if not all_news_articles:
all_news_articles = results
all_news_articles['articles'].extend(results['articles'])
# Ensuring to cover all pages by incrementing "page" value at each iteration
if params['page'] > results['total_pages']:
print("All articles have been extracted")
print(f'Proceed extracting page number => {params["page"]}')
print(f'ERROR: API call failed for page number => {params["page"]}')
print(f'Number of extracted articles => {str(len(all_news_articles))}')