Python 468 -> 398
- -50 because if it finds a broken url it gets a new random url
- -20 because it prints the title of each url visited (could change title -> url, but title is cleaner and actually makes my source larger)
It hangs every once and a while, can't figure out why. Perhaps Wikipedia rate limits?
I don't know if it will find the page in under an hour. I haven't had an hour to try it yet. If it takes longer than the allotted time, I'll edit my script...
I found the Boston Red Sox wikipedia page in 9 minutes 20 seconds, and the United States page in under 10 seconds, so it shouldn't take too long to find Code golf...
from mechanize import*;from lxml.html import*;from random import*;a=Browser();a.set_handle_robots(False);i='http://enwp.org/Special:Random';t='/wiki/Code_golf';d={};r='//div[@id="content"]//a/@href';l=fromstring
def f(o):
if o!=i:d[o]=o
if o in d:f(i)
try:v=l(a.open(o).read()).xpath(r)
except:v=l(a.open(i).read()).xpath(r)
print a.title()
if t in v:
a.open(t)
print 'f'
exit()
else:f(choice(v)) if v else f(i)
f(i)