Esempio n. 1
0
    def get_problem(self, *args, **kwargs):
        url = 'http://acm.wust.edu.cn/problem.php?id=' + str(kwargs['pid']) + '&soj=0'
        problem = Problem()
        try:
            website_data = Spider.get_data(url, self.code_type)

            problem.remote_id = kwargs['pid']
            problem.remote_url = url
            problem.remote_oj = 'WUST'
            problem.title = re.search(r': ([\s\S]*?)</h2>', website_data).group(1)
            problem.time_limit = re.search(r'(\d* Sec)', website_data).group(1)
            problem.memory_limit = re.search(r'(\d* MB)', website_data).group(1)
            problem.special_judge = re.search(r'class=red>Special Judge</span>', website_data) is not None
            soup = BeautifulSoup(website_data, 'lxml')

            # case:problem.picture=self.parse_html("img", soup, website_data)
            problem.description = self.parse_html("Description", soup, website_data)
            problem.input = self.parse_html("Input", soup, website_data)
            problem.output = self.parse_html("Output", soup, website_data)
            input_data = self.parse_html("Sample Input", soup, website_data)
            output_data = self.parse_html("Sample Output", soup, website_data)
            problem.hint = self.parse_html("HINT", soup, website_data)
            problem.author = self.parse_html("Author", soup, website_data)
            problem.source = self.parse_html("Source", soup, website_data)
            problem.sample = [
                {'input': input_data,
                 'output': output_data}]
        except:
            return Problem.PROBLEM_NOT_FOUND
        return problem
Esempio n. 2
0
    def get_problem(self, *args, **kwargs):
        url = 'http://acm.hdu.edu.cn/showproblem.php?pid=' + str(kwargs['pid'])
        problem = Problem()
        try:
            website_data = Spider.get_data(url, self.code_type)

            problem.remote_id = kwargs['pid']
            problem.remote_url = url
            problem.remote_oj = 'HDU'
            problem.title = re.search(r'color:#1A5CC8\'>([\s\S]*?)</h1>',
                                      website_data).group(1)
            problem.time_limit = re.search(r'(\d* MS)', website_data).group(1)
            problem.memory_limit = re.search(r'/(\d* K)',
                                             website_data).group(1)
            problem.special_judge = re.search(
                r'color=red>Special Judge</font>', website_data) is not None
            problem.description = re.search(
                r'>Problem Description</div>[\s\S]*?panel_content>([\s\S]*?)</div>',
                website_data).group(1)
            problem.input = re.search(
                r'>Input</div>[\s\S]*?panel_content>([\s\S]*?)</div>',
                website_data).group(1)
            problem.output = re.search(
                r'>Output</div>[\s\S]*?panel_content>([\s\S]*?)</div>',
                website_data).group(1)
            match_group = re.search(
                r'>Sample Input</div>[\s\S]*?panel_content>([\s\S]*?)</div',
                website_data)
            input_data = ''

            if match_group:
                input_data = re.search(r'(<pre><div[\s\S]*?>)?([\s\S]*)',
                                       match_group.group(1)).group(2)

            output_data = ''
            match_group = re.search(
                r'>Sample Output</div>[\s\S]*?panel_content>([\s\S]*?)</div',
                website_data)
            if match_group:
                output_data = re.search(r'(<pre><div[\s\S]*?>)?([\s\S]*)',
                                        match_group.group(1)).group(2)
                if re.search('<div', output_data):
                    output_data = re.search(r'([\s\S]*?)<div',
                                            output_data).group(1)
            problem.sample = [{'input': input_data, 'output': output_data}]

            match_group = re.search(
                r'>Author</div>[\s\S]*?panel_content>([\s\S]*?)</div>',
                website_data)
            if match_group:
                problem.author = match_group.group(1)
            match_group = re.search(
                r'<i>Hint</i>[\s\S]*?/div>[\s]*([\s\S]+?)</div>', website_data)
            if match_group:
                problem.hint = match_group.group(1)
        except:
            return Problem.PROBLEM_NOT_FOUND
        return problem