title: Scraping with BeautifulSoup for text -- NoneType error
body: <p>I am trying to get table data from wikipedia but I keep getting the error</p>
  
  <pre><code>AttributeError: 'NoneType' object has no attribute 'findAll'
  </code></pre>
  
  <p>Here is my code.</p>
  
  <pre><code>from bs4 import BeautifulSoup
  import urllib
  import urllib.request
  
  
  
  wiki = "https://en.wikipedia.org/wiki/List_of_current_United_States_Senators"
  page = urllib.request.urlopen(wiki)
  soup = BeautifulSoup(page, "lxml")
  
  name = ""
  party = ""
  state = ""
  picture = ""
  link = ""
  district = ""
  
  table = soup.find("table", { "class" : "wikitable sortable" })
  
  f = open('output.csv', 'w')
  
  for row in table.findAll("tr"):
      cells = row.findAll("td")
  
  
      state = cells[0].find(text=True)
      picture = cells[2].findAll(text=True)
      name = cells[3].find(text=True)
      party = cells[4].find(text=True)
  
  
      write_to_file = name + "," + state + "," + party + "," + link + "," + picture + "," + district + "\n"
      print (write_to_file)
      f.write(write_to_file)
  
  f.close()
  </code></pre>
  
  <p>Any help, even another way to do it (thought about using the wiki api but I'm rather lost on what to use), would be appreciated.</p>