Friday 18 November 2016

The Times of India News API

Today i will create a API which will bring you news from The Tim es of India news services .

URL used: http://timesofindia.indiatimes.com



This script will bring almost all the news data from this site .

Main Script :


import os , bs4,requests
b=requests.get('http://timesofindia.indiatimes.com/')
r=bs4.BeautifulSoup(b.content)
os.system('clear')
print 'Bellow are Lattest News:\n'
print r.find_all("ul",{"class":"list9"})[0].text.replace('\n\n','')
raw_input('Press Enter to go ahead: ')
os.system('clear')
print'\nLinks are given bellow:\n\n'
for i in r.find_all("ul",{"class":"list9"})[0].find_all('a'):
        print i.get('href')
raw_input('Press Enter to go ahead: ')
os.system('clear')
print '\nNews FROM ACROSS THE TIMES OF INDIA:\n'
for i in r.find_all("ul",{"data-vr-zone":"across_toi"})[0].find_all('a'):
        print i.text
raw_input('Press Enter to go ahead: ')
os.system('clear')
print'\nLinks are given bellow:\n\n'
for i in r.find_all("ul",{"data-vr-zone":"across_toi"})[0].find_all('a'):
        print i.get('href')
raw_input('Press Enter to go ahead: ')
os.system('clear')
print "Bellow is the TOP NEWS STORIES:"
print r.find_all("ul",{"class":"list8"})[0].text.replace('\n\n','')
raw_input('Press Enter to go ahead: ')
os.system('clear')
for i in r.find_all("ul",{"class":"list8"})[0].find_all('a'):
        print i.get('href')
raw_input('Press Enter to go ahead: ')
os.system('clear')
print 'Bellow is news from ENTERTAINMENT:'
for i in r.find_all("ul",{"class":"list8"})[1]:
        print i.text
raw_input('Press Enter to go ahead: ')
os.system('clear')
print 'Bellow are the links:'
for i in r.find_all("ul",{"class":"list8"})[1].find_all('a'):
        print i.get('href')
os.system('clear')
print '-----------------THE END---------------------'


Some of the output are given bellow :




Connect With Me: Facebook

No comments:

Post a Comment

Popular Posts