Exemplo n.º 1
0
    def parse_article(self, response):
        self.parse_article_count += 1
        Logging.info('======================%d' % self.parse_article_count)
        Logging.info(response.url)

        answer = Answer(response)

        Logging.info('author: %s' % answer.author())
        (contents, img_urls) = answer.content()
        Logging.info(contents)

        index = 0
        for url in img_urls:
            index += 1
            Logging.info(url)

            r = requests.get(url)
            if not os.path.exists('pic'):
                os.system('mkdir pic/')
            file_name = 'pic/' + answer.author() + '%d' % index + '.png'
            if r.status_code == 200:
                with open(file_name, 'w+') as f:
                    f.write(r.content)
                    f.close()

        return