from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
import random
import datetime
random.seed(datetime.datetime.now())
def linkaddr(addr) :
listing = []
html = urlopen("http://en.wikipedia.org"+addr)
bsObj = BeautifulSoup(html.read(), "html.parser")
for link in bsObj.find("div", {"id":"bodyContent"}).findAll("a",href=re.compile("^(/wiki/)((?!:).)*$")) :
if 'href' in link.attrs :
listing.append(link.attrs['href'])
return listing
links = []
links = linkaddr("/wiki/kevin_Bacon")
while len(links) > 0 :
a = links[random.randint(0, len(links)-1)]
print(a)
linkaddr(a)