-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import feedparser | ||
d = feedparser.parse('https://www.hindustantimes.com/rss/topnews/rssfeed.xml')#paste the link of web rss here to fetch the feed from site. | ||
print (d.feed.title) | ||
#FUNCTION TO GET HEADLINES FROM SITE AND STORE IT TO LIST BY ITERATINTING THROUGH FEED | ||
def getHeadlines( d ): | ||
headlines = [] | ||
for newsitem in d['items']: | ||
headlines.append(newsitem['title']) | ||
return headlines | ||
#PRINTING THE FEED TO TERMINAL WITH ENUMERATION TO EACH LINE | ||
for count,hl in enumerate(getHeadlines(d),start=1): | ||
print(count,hl) | ||
#WRITING THE FEED TO A CSV FILE WITH ENUMERATION TO EACH FEED | ||
with open("myfile.csv","w") as f: | ||
for count,hl in enumerate(getHeadlines(d),start=1): | ||
f.writelines('%d.'%count) | ||
f.writelines(hl+'\n') | ||
|