Python 427 -> 357
- -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...
import mechanize as m;import lxml.html as x;import random;a=m.Browser();a.set_handle_robots(False);p='http://en.m.wikipedia.org';i=p+'/wiki/Special:Random';t='/wiki/Code_golf'
def f(o):
r='//div[@id="content"]//a/@href';l=x.fromstring;
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(p+t)
print 'f'
else: f(p+random.choice(v)) if len(v)>0 else f(i)
f(i)