title: scraping wikipedia table - list of U.S. Senators
body: <p>I want to create a table where I can get the list of all U.S. Senators from the 116th Congress <a href="https://en.wikipedia.org/wiki/List_of_current_United_States_senators" rel="nofollow noreferrer">from the following wikipedia webpage</a>.</p>
  <p>As of now, I am using the following code.</p>
  <pre><code>from urllib.request import urlopen
  from bs4 import BeautifulSoup
  import requests
  import pandas as pd
  #import censusdata
  
  url = &quot;https://en.wikipedia.org/wiki/List_of_current_United_States_senators&quot;
  page = requests.get(url).content
  soup = BeautifulSoup(page, features = 'html.parser')
  table=soup.find(&quot;table&quot;, class_=&quot;wikitable sortable jquery-tablesorter&quot;)
  # print(table)
  state=[]
  senator=[]
  party=[]
  born=[]
  assumed_office=[]
  term=[]
  
  for row in table.find_all('tr')[1:]:
      col=row.find_all('td')
      col1=col[0].string.strip()
      state.append(col1)
      col2=col[2].string.strip()
      senator.append(col2)
      col3=col[3].string.strip()
      party.append(col2)
      col4=col[4].string.strip()
      born.append(col4)
      col5=col[7].string.strip()
      assumed_office.append(col5)
      col6=col[8].string.strip()
      term.append(col6)
  
  columns={'State':state,'Senator':senator,'Party Affiliated':party,'Birth Date':born,'Assumed Office':assumed_office,'Next Election':term}
  
  df = pd.DataFrame(columns)
  print(df)
  </code></pre>
  <p>However, I ended up getting this error.</p>
  <pre><code>Traceback (most recent call last):
    File &quot;c:\file_path\US Senate.py&quot;, line 23, in &lt;module&gt;
      for row in table.find_all('tr')[1:]:
  AttributeError: 'NoneType' object has no attribute 'find_all'
  </code></pre>
  <p>All I want to do is get the following data from each column: Name, the State the senator is representing, party affiliate, Age, when did they assume office, and when is their next election. Any assistance on this is truly appreciated.</p>