import json
import logging
import os
import requests
import shutil
import sys

class Scraper:
    """Scraper class."""

    logger = logging.getLogger("uoftscrapers")
    s = requests.Session()

    @staticmethod
    def ensure_location(location):
        """Ensure that the location given exists."""

        if not os.path.exists(location):
            os.makedirs(location)

    @staticmethod
    def save_json(data, location, filename):
        Scraper.ensure_location(location)

        with open('%s/%s.json' % (location, filename),'w+') as outfile:
            json.dump(data, outfile)

    @staticmethod
    def get_html(url, params=None, cookies=None, headers=None):
        """Fetches the HTML page source, automatically retrying if it times out."""

        html = None
        while html is None:
            try:
                r = Scraper.s.get(url, headers=headers)
                if r.status_code == 200:
                    html = r.text
            except (requests.exceptions.Timeout,
                    requests.exceptions.ConnectionError):
                continue

        return html.encode('utf-8')

    @staticmethod
    def flush_percentage(decimal):
        """Update the last line in stdout to a percentage formatted value."""

        sys.stdout.write('%.2f%%\r' % (decimal * 100))
        sys.stdout.flush()

    @staticmethod
    def get_text_from_class(soup, name):
        obj = soup.find(class_=name)
        if obj != None:
            return obj.get_text().replace('\xa0', ' ').strip()
        else:
            return ''

@@ -666,16 +666,33 @@
 ers=None
+, max_attempts=10
 ):%0A     
@@ -803,26 +803,75 @@
     
-while html is None
+attempts = 0%0A        while html is None and attempts %3C max_attempts
 :%0A  
@@ -923,16 +923,48 @@
 get(url,
+ params=params, cookies=cookies,
  headers
@@ -1048,16 +1048,60 @@
  r.text%0A
+                return html.encode('utf-8')%0A
         
@@ -1199,16 +1199,46 @@
 Error):%0A
+                attempts += 1%0A
         
@@ -1274,32 +1274,16 @@
 urn html
-.encode('utf-8')
 %0A%0A    @s

Update get_html