title: Exception Handling Python TypeError: 'NoneType' object is not callable
body: <p>I am <strong>scraping</strong> a list of urls with the same html format. Here is my <strong>scraper</strong></p>
  <pre><code>import requests, bs4, csv, json
  from pprint import pprint
  
  with open('playerslist.json') as data_file:
      data = json.load(data_file)
      for i in data['player']:
          name = i['player_name']
          url = 'https://www.capfriendly.com/players/'+name
          r = requests.get(url)
          soup = bs4.BeautifulSoup(r.text, 'lxml')
          table = soup.find(id=&quot;cont_x&quot;)
  
          with open(name+&quot;.csv&quot;, &quot;w&quot;, newline='') as team_data:
              def parse_td(td):
                  filtered_data = [tag.text for tag in td.find_all('span', recursive=False)
                                      if 'q' not in tag.attrs['class']]
                  return filtered_data[0] if filtered_data else td.text;
  
              for tr in table('tr', class_=['column_head', 'odd', 'even']):
                  row = [parse_td(td) for td in tr('td')]
                  writer = csv.writer(team_data)
                  writer.writerow(row)
  </code></pre>
  <p>The problem is that some of the url's (<code>https://www.capfriendly.com/players/'+name</code>) pages no longer exist. Which means that when I try to scrape them, I get the following error</p>
  <pre><code>    for tr in table('tr', class_=['column_head', 'odd', 'even']):
  TypeError: 'NoneType' object is not callable
  </code></pre>
  <p>I could make sure that my list of urls are all valid but I have 10000 urls to go through. That is why I am looking for a way to handle the exception, that way if a page no longer exists, it is skipped and the following url gets scraped.</p>
  <p>Also, if there is a more efficient way to store the data, please let me know.</p>