title: Python, BeautifulSoup - <div> text and <img> attributes in correct order
body: <p>I have a short piece of HTML that I would like to run through using BeautifulSoup. I've got basic navigation down, but this one has me stumped.</p>
  
  <p>Here's an example piece of HTML (totally made it up):</p>
  
  <pre><code>&lt;div class="textbox"&gt;
      Buying this item will cost you 
      &lt;img align="adsbottom" alt="1" src="/1.jpg;type=symbol"/&gt;
      silver credits and
      &lt;img align="adsbottom" alt="1" src="/1.jpg;type=symbol"/&gt;
      golden credits
  &lt;/div&gt;
  </code></pre>
  
  <p>Using the 'alt' attributes of the img tags I would like to see the following result:
  <em>Buying this item will cost you 1 silver credits and 1 golden credits</em></p>
  
  <p>I have no idea how to loop through the div-tag sequentially. I can do the following to extract all the text contained in the div-tag</p>
  
  <pre><code>html = BeautifulSoup(string)
  print html.get_text()
  </code></pre>
  
  <p>to get all the text contained in the div-tag, but that would give me result like this:
  <em>Buying this item will cost you  silver credits and  golden credits</em></p>
  
  <p>Likewise, I can get the values of the alt-attributes from the img-tags by doing this:</p>
  
  <pre><code>html = BeautifulSoup(string).img
  print html['alt']
  </code></pre>
  
  <p>But of course this only gives me the attribute value.</p>
  
  <p>How can I iterate through all these elements in the correct order? Is it possible to read the text in the div-element and the attibutes of the img-element in consecutive order?</p>