def solve(problem_id, prompt): source = urllib.request.urlopen(hacker_org_util.build_challenge_url(problem_id)).read().decode() answer = re.search(r'{prompt}.*<b>(.*)</b>'.format(prompt=prompt), source, flags=re.DOTALL).group(1).strip() print(answer) print(urllib.request.urlopen(hacker_org_util.build_challenge_url(problem_id, answer)).read().decode())
def main(): url = 'http://whitehouse.gov' print('get url:', hacker_org_util.build_challenge_url(PROBLEM_ID, url)) request = urllib.request.Request(hacker_org_util.build_challenge_url(PROBLEM_ID, url), headers={'Referer': url}) print(urllib.request.urlopen(request).read().decode())
def solve(problem_id, prompt, post_process=lambda s:s): source = urllib.request.urlopen(hacker_org_util.build_challenge_url(problem_id)).read().decode() answer = post_process(re.search(r'{prompt}.*<b>(.*)</b>'.format(prompt=prompt), source, flags=re.DOTALL).group(1).strip()) print(answer) print(urllib.request.urlopen(hacker_org_util.build_challenge_url(problem_id, answer)).read().decode())
def main(): source = urllib.request.urlopen( hacker_org_util.build_challenge_url(PROBLEM_ID)).read().decode() directions = re.findall(r'(?<=<img src="img/.).(?=.\.gif">)', source, flags=re.DOTALL) out_image = Image.new('1', (300, 30)) x, y = 10, 10 out_image.putpixel((x, y), 1) for direction in directions: for _ in range(5): if direction == 'u': y -= 1 elif direction == 'r': x += 1 elif direction == 'd': y += 1 else: x -= 1 out_image.putpixel((x, y), 1) out_image.show() out_image.close()
def main(): source = urllib.request.urlopen(hacker_org_util.build_challenge_url(PROBLEM_ID)).read().decode() m = re.search('<p>(.*)<p>', source, flags=re.DOTALL) text = m.group(1) print(''.join(re.findall(r'[A-Z]', text)))
def main(): source = urllib.request.urlopen( hacker_org_util.build_challenge_url(PROBLEM_ID)).read().decode() m = re.search('<p>(.*)<p>', source, flags=re.DOTALL) text = m.group(1) print(''.join(re.findall(r'[A-Z]', text)))
def main(): urllib.request.urlopen(hacker_org_util.build_challenge_url(PROBLEM_ID)) local_filename = urllib.request.urlretrieve( 'http://www.hacker.org/challenge/misc/stars.php')[0] image = Image.open(local_filename) answer = '' for y in range(8, image.size[1], 16): answer += chr( int(''.join( map( lambda x: '1' if image.getpixel((x, y)) == (230, 230, 230) else '0', range(8, image.size[0], 16))), base=2)) print(answer) print( urllib.request.urlopen( hacker_org_util.build_challenge_url(PROBLEM_ID, answer)).read().decode())
def main(): source = urllib.request.urlopen(hacker_org_util.build_challenge_url(PROBLEM_ID)).read().decode() directions = re.findall(r'(?<=<img src="img/.).(?=.\.gif">)', source, flags=re.DOTALL) out_image = Image.new('1', (300, 30)) x, y = 10, 10 out_image.putpixel((x, y), 1) for direction in directions: for _ in range(5): if direction == 'u': y -= 1 elif direction == 'r': x += 1 elif direction == 'd': y += 1 else: x -= 1 out_image.putpixel((x, y), 1) out_image.show() out_image.close()
def main(): print(urllib.request.urlopen(hacker_org_util.build_challenge_url(PROBLEM_ID, 'marmelade'), data=b'').read().decode())