title: Python, beautifulsoup: extract text from table cell
body: <p>I try to extract the table from <a href="http://en.wikipedia.org/wiki/Visa_requirements_for_Belarusian_citizens" rel="nofollow">wikipedia</a> using the following code:</p>
  
  <pre><code>import urllib2
  
  from bs4 import BeautifulSoup
  
  file = open('belarus_wiki.txt', 'w')
  
  url = "http://en.wikipedia.org/wiki/Visa_requirements_for_Belarusian_citizens"
  page = urllib2.urlopen(url)
  
  soup = BeautifulSoup(page)
  
  country = ""
  visa = ""
  notes = ""
  
  table = soup.find("table", "sortable wikitable")
  for row in table.findAll("tr"):
      cells = row.findAll("td")
      if len(cells) == 3:
          country = cells[0].findAll(text=True)
          visa = cells[1].findAll(text=True)
          notes = cells[2].find(text=True)
  
          print country[1].encode("utf-8"), visa[0].encode("utf-8"), notes[0].encode("utf-8")
  
          file.write(country[1].encode("utf-8") + ',' + visa[0].encode("utf-8") + '\n')
  
  file.close()
  </code></pre>
  
  <p>But I see the error message:</p>
  
  <pre><code>Traceback (most recent call last):
  File "...\belarus_wiki.py", line 27, in &lt;module&gt;
  print country[1].encode("utf-8"), visa[0].encode("utf-8"), notes[0].encode("utf-8")
  IndexError: list index out of range
  </code></pre>
  
  <p>Please tell me how to extract all the text from these cells?</p>