@@ -0,0 +1,2456 @@
+# pylint:disable=C0111%0Aimport itertools%0Aimport os%0Aimport re%0Aimport tempfile%0Aimport urllib%0A%0A%0ACATEGORIES = %5B%0A    'Architectural drawings',%0A    'Architecture',%0A    'Book',%0A    'Coins',%0A    'Decorative Arts',%0A    'Drawings',%0A    'Figures (illustrations)',%0A    'Illuminations',%0A    'Implements',%0A    'Jewelry',%0A    'Manuscripts',%0A    'Mixed Material',%0A    'Paintings',%0A    'Photographs',%0A    'Plates (illustrations)',%0A    'Playing cards',%0A    'Prints',%0A    'Sculpture',%0A    'Vessels',%0A    'Visual Material',%0A    'Watercolors (paintings)',%0A%5D%0A%0A%0Adef _tmpfile(suffix='', prefix='tmp', directory=None):%0A    filehandle, filename = tempfile.mkstemp(suffix, prefix, directory)%0A    os.close(filehandle)%0A    return filename%0A%0A%0Aclass Scraper(object):%0A    def __init__(self, category, batchsize=100, page=1):%0A        self._category = category%0A        self._batchsize = batchsize%0A        self._page = page%0A%0A    @classmethod%0A    def format_filename(cls, url, basedir=None):%0A        basename = os.path.basename(url)%0A        return (_tmpfile(basename) if basedir is None%0A                else os.path.join(basedir, basename))%0A%0A    @classmethod%0A    def extract_images(cls, resultspage):%0A        image_re = re.compile(r'%22(?P%3Curl%3Ehttp://www.getty.edu/art/collections'%0A                              r'/images/enlarge/%5B%5E%22%5D+)%22')%0A        return set(match.group('url') for line in resultspage%0A                   for match in image_re.finditer(line))%0A%0A    def resultspage(self, page):%0A        url_template = (r'http://search.getty.edu/gateway/search'%0A                        r'?q&cat=type&dir=s&img=1'%0A                        r'&types=%22%7Bcategory%7D%22&rows=%7Bbatchsize%7D&pg=%7Bpage%7D')%0A        url = url_template.format(%0A            category=self._category,%0A            batchsize=self._batchsize,%0A            page=page)%0A        return urllib.urlopen(url)%0A%0A    def scrape(self, num=None, basedir=None):%0A        filenames = %5B%5D%0A        for image_url in itertools.islice(self, num):%0A            filename = self.format_filename(image_url, basedir)%0A            urllib.urlretrieve(image_url, filename)%0A            filenames.append(filename)%0A        return filenames%0A%0A    def __iter__(self):%0A        while True:%0A            resultspage = self.resultspage(self._page)%0A            image_urls = self.extract_images(resultspage)%0A            if image_urls:%0A                for image_url in image_urls:%0A                    yield image_url%0A                self._page += 1%0A            else:%0A                break%0A

Implement getty.edu image scraper