def get_problem(self, *args, **kwargs): url = 'http://poj.org/problem?id=' + str(kwargs['pid']) problem = Problem() try: res = self.request.get(url=url) website_data = res.text problem.remote_id = kwargs['pid'] problem.remote_url = url problem.remote_oj = 'POJ' # print('probid', problem.remote_id) problem.title = re.search(r'ptt" lang="en-US">([\s\S]*?)</div>', website_data).group(1) problem.time_limit = re.search(r'(\d*MS)', website_data).group(1) problem.memory_limit = re.search(r'Memory Limit:</b> ([\s\S]*?)</td>', website_data).group(1) problem.special_judge = re.search(r'red;">Special Judge</td>', website_data) is not None problem.description = re.search(r'>Description</p>[\s\S]*?lang="en-US">([\s\S]*?)</div>', website_data).group(1) problem.input = re.search(r'>Input</p>[\s\S]*?lang="en-US">([\s\S]*?)</div>', website_data).group(1) problem.output = re.search(r'>Output</p>[\s\S]*?lang="en-US">([\s\S]*?)</div>', website_data).group(1) match_group = re.search(r'>Sample Input</p>([\s\S]*?)<p class', website_data) input_data = '' if match_group: input_data = re.search('"sio">([\s\S]*?)</pre>', match_group.group(1)).group(1) output_data = '' match_group = re.search(r'>Sample Output</p>([\s\S]*?)<p class', website_data) if match_group: output_data = re.search('"sio">([\s\S]*?)</pre>', match_group.group(1)).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'>Hint</p>[\s\S]*?"en-US">([\s\S]*?)</div>', website_data) if match_group: problem.hint = match_group.group(1) match_group = re.search(r'>Source</p>[\s\S]*?"en-US">([\s\S]*?)</div>', website_data) if match_group: problem.source = match_group.group(1) return problem except: pass return None
def get_problem(self, *args, **kwargs): url = 'http://acm.hdu.edu.cn/showproblem.php?pid=' + str(kwargs['pid']) problem = Problem() try: website_data = self.request.get(url) self.cookies = website_data.cookies 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.text).group(1) problem.time_limit = re.search(r'(\d* MS)', website_data.text).group(1) problem.memory_limit = re.search(r'/(\d* K)', website_data.text).group(1) problem.special_judge = re.search(r'color=red>Special Judge</font>', website_data.text) is not None problem.description = re.search(r'>Problem Description</div>[\s\S]*?panel_content>([\s\S]*?)</div>', website_data.text).group(1) problem.input = re.search(r'>Input</div>[\s\S]*?panel_content>([\s\S]*?)</div>', website_data.text).group(1) problem.output = re.search(r'>Output</div>[\s\S]*?panel_content>([\s\S]*?)</div>', website_data.text).group( 1) match_group = re.search(r'>Sample Input</div>[\s\S]*?panel_content>([\s\S]*?)</div', website_data.text) 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.text) 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.text) 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.text) if match_group: problem.hint = match_group.group(1) except: return None return problem