

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Journalists who report Fake news will lose their accreditation !!
- What is the latest news from SBI regarding minimum balance?
- Are media houses working on the news only for TRPs?
- How to select record from last 6 months in a news table using MySQL?
- 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.
- Fetching object keys using recursion in JavaScript
- Speech Recognition in Python using Google Speech API
- Fetching text from Wikipedia’s Infobox in Python
- Bigg Boss Telugu creating news as Nani slaps a legal case on Sri Reddy for defamation and demands unconditional apology within 7 days
- Get emotions of images using Microsoft emotion API in Python?
- Multithreaded using the Pthreads API
- How to Add Cucumber Layer on Top of REST-assured API Tests?
Advertisements