title: Looping through elements with Beautifulsoup
body: <p>I'm trying to store some data that's scraped from a website. The data I need is the text from the element, to then store in a csv for querying later on. </p>
  
  <p>In the code below, I'm finding all references to the class 'vip'. Then I want to loop through those to strip away the unnecessary HTML to get the text data only. Finally I encode it with utf-8, ready to be inserted into a csv.  </p>
  
  <pre><code># parse the page and store in var soup
  soup = BeautifulSoup(page, 'html.parser')
  
  # find the title
  title_box = soup.findAll('a', attrs={'class': 'vip'}}
  
  print title_box
  
  # loop through each iteration
  for each in title_box:
      if each.find('title_box'):
          title = title_box.text.strip().encode('utf-8')
  
  # print the result
  print title
  </code></pre>
  
  <p>However whenever I print the result of 'title' I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/Users/XXXX/Projects/project-kitchenaid/scaper.py", line 28, in &lt;module&gt;
      print title
  NameError: name 'title' is not defined
  </code></pre>
  
  <p>From what I understand, <code>title</code> is out of scope. How do I retrieve the the data from the loop and write it to a print call? </p>
  
  <p>For context, this is just one result of <code>print title_box</code>:</p>
  
  <pre><code>&lt;a class="vip" href="http://www.ebay.co.uk/itm/KITCHENAID-CLASSIC-MIXER-5K45SS-ATTACHMENTS-AND-INSTRUCTIONS-/302468759209?hash=item466c8afea9:g:2PIAAOSwCi9Zvk2D" title="Click this link to access KITCHENAID CLASSIC MIXER 5K45SS - ATTACHMENTS AND INSTRUCTIONS"&gt;KITCHENAID CLASSIC MIXER 5K45SS - ATTACHMENTS AND INSTRUCTIONS&lt;/a&gt;]
  </code></pre>