News API is a simple HTTP REST API for searching and retrieving live news articles from all over the web. Using this, one can fetch the top stories running on any news website or can search top news on a specific topic (or keyword).
News can be retrieved based on some criteria. Say the topic (keyword) to be searched is ‘Geeksforgeeks’ or might be concerned to a specific channel. All can be done, but the API key is needed to get started.
Steps : 1. Visit https://newsapi.org/ to get your own API key. 2. Install requests package.
Below is the implementation of above idea :
# importing requests package import requests def NewsFromBBC(): # BBC news api main_url = " https://newsapi.org/v1/articles?source=bbc-news&sortBy;=top&apiKey;=4dbc17e007ab436fb66416009dfb59a8" # fetching data in json format open_bbc_page = requests.get(main_url).json() # getting all articles in a string article article = open_bbc_page["articles"] # empty list which will # contain all trending news results = [] for ar in article: results.append(ar["title"]) for i in range(len(results)): # printing all trending news print(i + 1, results[i]) #to read the news out loud for us from win32com.client import Dispatch speak = Dispatch("SAPI.Spvoice") speak.Speak(results) # Driver Code if __name__ == '__main__': # function call NewsFromBBC() |
Output :
1 Italy to lift coronavirus travel restrictions 2 White House 'Operation Warp Speed' to look for Covid jab 3 Two Americas in the nation's capital 4 Kobe Bryant helicopter crash post-mortem released 5 Little things people are doing while socially distanced 6 The last 'normal' photo on your phone 7 'They came to kill the mothers' 8 EU-UK Brexit trade talks in trouble 9 Trial starts to see if dogs can 'sniff out' virus 10 Beatles photographer Astrid Kirchherr dies aged 81
Note : Output may change based on the top articles at time.
Recommended Posts:
- Build an Application to extract news from Google News Feed Using Python
- Newspaper scraping using Python and News API
- Fetching recently sent mails details sent via a Gmail account using Python
- Fetching text from Wikipedia's Infobox in Python
- Python Django | Google authentication and Fetching mails from scratch
- Read latest news using newsapi | Python
- Scrape most reviewed news and tweet using Python
- Implementing News Parser using Template Method Design Pattern in Python
- EdgeRank Algorithm - Algo behind Facebook News Feed
- Python Desktop News Notifier in 20 lines
- Facebook News Feed Algorithm
- Python | Django News App
- Speech Recognition in Python using Google Speech API
- Python | Get a set of places according to search query using Google Places API
- Get emotions of images using Microsoft emotion API in Python
- Python | URL shortener using tinyurl API
- Python | Find current weather of any city using openweathermap API
- Python | Calculate geographic coordinates of places using google geocoding API
- Python | Get a google map image of specified location using Google Static Maps API
- Python | How to shorten long URLs using Bitly API
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : araxk19

