Hi!
Im trying to fix a Python script which takes the posts from a specific RSS feed and strips them down and inputs them into a text file. As you can see beneath, there are two main print functions. One prints only to the shell once run, but it shows all of the posts, which is what I want it to do. Now, the second part is where the problem lies. It only prints out the last post of the RSS feed into a text, not the whole thing, as the first function does. I've also tried to make the second function (f = open()) the same way as the first with the %s instead of a new print-line pr. variable.
If anyone could tell me why the script doesnt post more than one (the last) post of the RSS feed into the text, but the whole thing in the shell, and what modifications I need to fix it, I would really appreciate it :)
Here is the code:
import urllib
import sys
import xml.dom.minidom
#The url of the feed
address = 'http://www.vg.no/export/Alle/rdf.hbs?kat=nyheter'
#Our actual xml document
document = xml.dom.minidom.parse(urllib.urlopen(address))
for item in document.getElementsByTagName('item'):
title = item.getElementsByTagName('title')[0].firstChild.data
link = item.getElementsByTagName('link')[0].firstChild.data
description = item.getElementsByTagName('description')[0].firstChild.data
str = link.strip("http://go.vg.no/cgi-bin/go.cgi/rssart/")
print "\n"
print "------------------------------------------------------------------"
print '''"%s"\n\n%s\n\n(%s)''' % (title.encode('UTF8', 'replace'),
description.encode('UTF8','replace'),
str.encode('UTF8','replace'))
print "------------------------------------------------------------------"
print "\n"
f = open('lawl.txt','w')
print >>f, "----------------------Nyeste paa VG-------------------------------"
print >>f, title.encode('UTF8','replace')
print >>f, description.encode('UTF8','replace')
print >>f, str.encode('UTF8','replace')
print >>f, "------------------------------------------------------------------"
print >>f, "\n"