old_contents: from bs4 import BeautifulSoup
  import requests
  import sys
  import re
  
  
  INSPECTION_DOMAIN = 'http://info.kingcounty.gov'
  INSPECTION_PATH = '/health/ehs/foodsafety/inspections/Results.aspx'
  INSPECTION_PARAMS = {
      'Output': 'W',
      'Business_Name': '',
      'Business_Address': '',
      'Longitude': '',
      'Latitude': '',
      'City': '',
      'Zip_Code': '',
      'Inspection_Type': 'All',
      'Inspection_Start': '',
      'Inspection_End': '',
      'Inspection_Closed_Business': 'A',
      'Violation_Points': '',
      'Violation_Red_Points': '',
      'Violation_Descr': '',
      'Fuzzy_Search': 'N',
      'Sort': 'H'
  }
  
  
  def get_inspection_page(**kwargs):
      """Return kingcounty inspection page and encoding."""
      url = INSPECTION_DOMAIN + INSPECTION_PATH
      params = INSPECTION_PARAMS.copy()
      for key, value in kwargs.items():
          if key in INSPECTION_PARAMS:
              params[key] = value
      resp = requests.get(url, params=params)
      resp.raise_for_status()
      return resp.content, resp.encoding
  
  
  def load_inspection_page(file):
      """Returns html in load_inspection.html and encoding."""
      with open(file, 'r') as infile:
          html = infile.read()
      return html, 'utf-8'
  
  
  def parse_source(html, encoding='utf-8'):
      return BeautifulSoup(html, from_encoding=encoding)
  
  
  def extract_data_listing(html):
      """Extract listing for each restaurant."""
      id_finder = re.compile(r'PR[\d]+~')
      return html.find_all('div', id=id_finder)
  
  
  def has_two_tds(elem):
      is_tr = elem.name == 'tr'
      td_children = elem.find_all('td', recursive=False)
      has_two = len(td_children) == 2
      return is_tr and has_two
  
  
  if __name__ == '__main__':
      kwargs = {
          'Inspection_Start': '2/1/2013',
          'Inspection_End': '2/1/2015',
          'Zip_Code': '98109'
      }
      if len(sys.argv) > 1 and sys.argv[1] == 'test':
          html, encoding = load_inspection_page('load_inspection.html')
      else:
          html, encoding = get_inspection_page(**kwargs)
      doc = parse_source(html, encoding)
      listings = extract_data_listing(doc)
      for listing in listings:
          metadata_rows = listing.find('tbody').find_all(has_two_tds, recursive=False)
          print len(metadata_rows)
  
new_contents: from bs4 import BeautifulSoup
  import requests
  import sys
  import re
  
  
  INSPECTION_DOMAIN = 'http://info.kingcounty.gov'
  INSPECTION_PATH = '/health/ehs/foodsafety/inspections/Results.aspx'
  INSPECTION_PARAMS = {
      'Output': 'W',
      'Business_Name': '',
      'Business_Address': '',
      'Longitude': '',
      'Latitude': '',
      'City': '',
      'Zip_Code': '',
      'Inspection_Type': 'All',
      'Inspection_Start': '',
      'Inspection_End': '',
      'Inspection_Closed_Business': 'A',
      'Violation_Points': '',
      'Violation_Red_Points': '',
      'Violation_Descr': '',
      'Fuzzy_Search': 'N',
      'Sort': 'H'
  }
  
  
  def get_inspection_page(**kwargs):
      """Return kingcounty inspection page and encoding."""
      url = INSPECTION_DOMAIN + INSPECTION_PATH
      params = INSPECTION_PARAMS.copy()
      for key, value in kwargs.items():
          if key in INSPECTION_PARAMS:
              params[key] = value
      resp = requests.get(url, params=params)
      resp.raise_for_status()
      return resp.content, resp.encoding
  
  
  def load_inspection_page(file):
      """Returns html in load_inspection.html and encoding."""
      with open(file, 'r') as infile:
          html = infile.read()
      return html, 'utf-8'
  
  
  def parse_source(html, encoding='utf-8'):
      return BeautifulSoup(html, from_encoding=encoding)
  
  
  def extract_data_listing(html):
      """Extract listing for each restaurant."""
      id_finder = re.compile(r'PR[\d]+~')
      return html.find_all('div', id=id_finder)
  
  
  def has_two_tds(elem):
      is_tr = elem.name == 'tr'
      td_children = elem.find_all('td', recursive=False)
      has_two = len(td_children) == 2
      return is_tr and has_two
  
  
  def clean_data(td):
      data = td.string
      try:
          return data.strip(" \n:-")
      except AttributeError:
          return u""
  
  if __name__ == '__main__':
      kwargs = {
          'Inspection_Start': '2/1/2013',
          'Inspection_End': '2/1/2015',
          'Zip_Code': '98109'
      }
      if len(sys.argv) > 1 and sys.argv[1] == 'test':
          html, encoding = load_inspection_page('load_inspection.html')
      else:
          html, encoding = get_inspection_page(**kwargs)
      doc = parse_source(html, encoding)
      listings = extract_data_listing(doc)
      for listing in listings:
          metadata_rows = listing.find('tbody').find_all(has_two_tds, recursive=False)
          for row in metadata_rows:
              for td in row.find_all('td', recursive=False):
                  print repr(clean_data(td)),
              print
          print
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
subject: Add method to clean up parsed data.