Home > Python, PythonChallenge.Com > PythonChallenge – Level 4

PythonChallenge – Level 4


Homepagehttp://www.pythonchallenge.com/pc/def/linkedlist.php

How I solve:

– See nothing special on page, so I open to view source and found this interesting part:

<a href="linkedlist.php?nothing=12345"><img src="chainsaw.jpg" border="0"/></a>

Pasting this on browser, or simple just by clicking onto the image, a hint appears:

and the next nothing is 44827

– Update the URL place replacing the number ‘12345’ by ‘44827’, well, funny thing is that it updates a new number, it just like updates forever …handily @@.
– Since it’s a scripting challenge, so I write a script to handle this task. (anyway, on the page source it’s already mentioned not to use hands, it might run for 400+ times…)

import re
import urllib

target = 12345
TARGET_URL = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="
while True:
	source = urllib.urlopen("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" + str(target)).read()
	found = re.findall('[0-9]+', source)
	if found:
		target = found[-1]
		print target
	else:
		print source

– It’s running as expected; however, at some point it stops:

Yes. Divide by two and keep going.

– Then update the script -> 8022.

import re
import urllib

target = 8022
TARGET_URL = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="
while True:
	source = urllib.urlopen("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" + str(target)).read()
	found = re.findall('[0-9]+', source)
	if found:
		target = found[-1]
		print target
	else:
		print source

– Finally, got this stuff: “peak.html” , reaching to the next level 😀

Cheers,
Pete Houston

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: