Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this Python script only read the last RSS post into the file?
    primarykey
    data
    text
    <p>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 <em>all</em> 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 <em>last</em> 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.</p> <p>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 :)</p> <p>Here is the code:</p> <pre><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 &gt;&gt;f, "----------------------Nyeste paa VG-------------------------------" print &gt;&gt;f, title.encode('UTF8','replace') print &gt;&gt;f, description.encode('UTF8','replace') print &gt;&gt;f, str.encode('UTF8','replace') print &gt;&gt;f, "------------------------------------------------------------------" print &gt;&gt;f, "\n" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload