Skip to content

Instantly share code, notes, and snippets.

@Abhayparashar31
Last active December 11, 2020 04:49
Show Gist options
  • Save Abhayparashar31/3f1f425fef426c7d54a43348b660f0b6 to your computer and use it in GitHub Desktop.
Save Abhayparashar31/3f1f425fef426c7d54a43348b660f0b6 to your computer and use it in GitHub Desktop.
import requests
url = " http://newsapi.org/v2/top-headlines?country=us&apiKey=YOU_API_KEY"
page = requests.get(url).json()
article = page["articles"]
results = []
for ar in article:
results.append(ar["title"])
for i in range(10): ### Top 10 News ### Use len(results) to get all the top 20 news
print(i + 1, results[i])
---------------------------------------
1 Live: The Game Awards tease new ‘League of Legends’ title and ‘Among Us’ map, plus Master Chief in ‘Fortnite’ - The Washington Post
2 Kenny Young's 79-yard pick-six has Rams rolling against Patriots - ESPN
3 Mike Lee blocks legislation to create Smithsonian museums for Latinos and women - POLITICO
4 The 52 biggest Marvel, Star Wars, and Disney announcements from its end of year event - The Verge
5 Body cam footage shows raid on former Florida Covid data scientist's home - CNN
6 Ari Fleischer: Mainstream media committed 'dereliction of duty' by not reporting on Hunter Biden - Fox News
7 Powerful Delta IV Heavy rocket launches secret US spy satellite to orbit - Space.com
8 'I literally lost it': Kim Kardashian reacts to Brandon Bernard's scheduled execution, details last phone call - USA TODAY
9 N.H. House Speaker Dick Hinch died of COVID-19, medical examiner says - The Boston Globe
10 DGA Tells WarnerMedia That Deal To Release 2021 Warner Bros Movie Slate On HBO Max Is “Unacceptable” – Read The Full Letter - Deadline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment