
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Fetching top news using news API in Python
News API is very famous API for searching and fetching news articles from any web site, using this API anyone can fetch top 10 heading line of news from any web site.
But using this API, one thing is required which is the API key.
Example Code
import requests def Topnews(): # BBC news api my_api_key="Api_number” my_url = = " https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=my_api_key" my_open_bbc_page = requests.get(my_url).json() my_article = my_open_bbc_page["articles"] my_results = [] for ar in my_article: my_results.append(ar["title"]) for i in range(len(my_results)): print(i + 1, my_results[i]) # Driver Code if __name__ == '__main__': # function call Topnews()

Using Panda
Using pandas DataFrame is much easier to work with down the road, we can easily convert from JSON to DataFrame using pd.DataFrame.from_dict and .appy([pd.Series]).

- Related Articles
- Bad News vs Serious News
- Health News: Latest Research, Top Stories, Trending Topics
- Media Strategies Used by News
- Content-Based Approaches to News Media
- Technical SEO For News Websites: A Comprehensive Guide
- A simple News app with Tkinter and Newsapi
- How to select record from last 6 months in a news table using MySQL?
- Journalists who report Fake news will lose their accreditation !!
- Are media houses working on the news only for TRPs?
- What is the latest news from SBI regarding minimum balance?
- How to Use Technical SEO to Optimize for Google News
- C++ Program to check April fool news is fake or real
- Great news for NTR big fans - The Biopic Launch on 29th March
- How FullFact is Planning to end Circulation of Fake news on Internet
- Breaking News: Major relief to Passport Applicants as Passport procedure became faster and easier.

Advertisements