Python 373 -> 303
ReadsIt reads the wikipediaWikipedia destination from input()
(user input), and should be in the format of /wiki/dest
. So, something like /wiki/Code_golf
or /wiki/United_States
. It also uses 1 spacesone space for the indents and http://enwp.org
instead of wikipedia'sWikipedia's full URL to save bytes.
- -50 because if it finds a broken urlURL it gets a new random urlURL.
- -20 because it prints the title of each urlURL visited (could change title -> urlURL, but title is cleaner and actually makes my source larger).
It hangs every once and a while, and I can't figure out why. Perhaps because of Wikipedia rate limits?
I found the Boston Red Sox wikipedia pageBoston 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 golfGolf...
from mechanize import*;from lxml.html import*;from random import*;a=Browser();a.set_handle_robots(0);i='http://enwp.org/Special:Random';t=input();d={};k=a.open
def f(o):
if o!=i:d[o]=o
if o in d:f(i)
try:v=fromstring(k(o).read()).xpath('//div[@id="content"]//a/@href')
except:f(i)
print a.title()
if t in v:k(t);print 'f';exit()
else:f(choice(v)) if v else f(i)
f(i)