title: how to 'clean' all the entries in a feedparser feed
body: <p>I backed up my blog in Google's XML format. It's quite long. So far, I have done this:</p>
  
  <pre><code>&gt;&gt;&gt; import feedparser
  &gt;&gt;&gt; blogxml = feedparser.parse('blog.xml')
  &gt;&gt;&gt; type(blogxml)
  &lt;class 'feedparser.FeedParserDict'&gt;
  </code></pre>
  
  <p>In the book I'm reading, the author does this:</p>
  
  <pre><code>&gt;&gt;&gt; import feedparser
  &gt;&gt;&gt; llog = feedparser.parse("http://languagelog.ldc.upenn.edu/nll/?feed=atom")
  &gt;&gt;&gt; llog['feed']['title'] u'Language Log'
  &gt;&gt;&gt; len(llog.entries) 15
  &gt;&gt;&gt; post = llog.entries[2]
  &gt;&gt;&gt; post.title u"He's My BF"
  &gt;&gt;&gt; content = post.content[0].value
  &gt;&gt;&gt; content[:70] u'&lt;p&gt;Today I was chatting with three of our visiting graduate students f'
  &gt;&gt;&gt; nltk.word_tokenize(nltk.html_clean(content))
  </code></pre>
  
  <p>And that works for me on an entry-by-entry basis. As you can see, I've already got a way of cleaning HTML using the NLTK. But what I really want is to grab all the entries, clean them of HTML (which I already know how to do and am not asking how to do, read the question a bit more carefully please), and write them to a file as a plaintext string. Which has more to do with using feedparser correctly. Is there a simple way to do that?</p>
  
  <p>Update:</p>
  
  <p>I'm still no closer, as it turns out, to finding an easy way to do it. Due to my ineptitude with python, I was forced to do something a bit ugly.</p>
  
  <p>This is what I thought I'd do:</p>
  
  <pre><code>import feedparser
  import nltk
  
  blog = feedparser.parse('myblog.xml')
  
  with open('myblog','w') as outfile:
      for itemnumber in range(0, len(blog.entries)):
          conts = blog.entries[itemnumber].content
          cleanconts = nltk.word_tokenize(nltk.html_clean(conts))
          outfile.write(cleanconts)
  </code></pre>
  
  <p>So, thank you very much, @Rob Cowie, but your version (which looks great) did not work. I feel bad for not pointing that out earlier, and for accepting the answer, but I don't have much time to work on this project. The stuff I put below is all I could get to work, but I'm leaving this question open in case someone has something more elegant.</p>
  
  <pre><code>import feedparser
  import sys
  
  blog = feedparser.parse('myblog.xml')
  sys.stdout = open('blog','w')
  
  for itemnumber in range(0, len(blog.entries)):
      print blog.entries[itemnumber].content
  
  sys.stdout.close()
  </code></pre>
  
  <p>then I CTRL-D'ed out of the interpreter, because I had no idea how to close the open file without closing Python's stdout. Then I re-entered the interpreter, opened the file, read the file, and cleaned the HTML from there. (nltk.html_clean is a typo in the online version of the NLTK book itself, by the way... it's actually nltk.clean_html). What I ended up with was almost, but not quite, plaintext.</p>