-
Notifications
You must be signed in to change notification settings - Fork 0
/
news_extractor.py~
42 lines (36 loc) · 1.09 KB
/
news_extractor.py~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import newspaper
import csv
class newsExtractor(object):
"""docstring for newsExtractor"""
def __init__(self, url):
self.url = url
self.paper = newspaper.build(url,memoize_articles=False)
self.result=[["Title","Article"]]
print("initialized successfully")
def extract_article(self):
length = self.paper.size()
for i in range(length):
#print(i)
article=self.paper.articles[i]
article.download()
article.parse()
articleText=article.text
articleTitle=article.title
self.result.append([articleTitle,articleText])
print("extracted successfully")
def store_result(self,filename):
with open(filename,'w') as f:
w= csv.writer(f)
for row in self.result:
w.writerow(row)
#urls = ['','','','','','','',]
hindustan_times = newsExtractor("http://indianexpress.com/")
hindustan_times.extract_article()
hindustan_times.store_result("ie_7_Aug.csv")
#http://www.hindustantimes.com/
#http://www.thehindu.com/
#http://timesofindia.indiatimes.com/
#http://www.tribuneindia.com/
#http://indianexpress.com/
#http://economictimes.indiatimes.com/
#http://www.deccanherald.com/