Demo entry 6185676



Submitted by anonymous on Oct 11, 2016 at 03:55
Language: Python 3. Code size: 561 Bytes.

from urllib.request import urlopen
from bs4 import BeautifulSoup
import datetime
import random
import re
def getLinks(articleUrl):
    html = urlopen(""+articleUrl)
    bsObj = BeautifulSoup(html)
    return bsObj.find("div", {"id":"bodyContent"}).findAll("a", href=re.compile("^(/wiki/)((?!:).)*$"))
links = getLinks("/wiki/Kevin_Bacon")
while len(links) > 0:
    newArticle = links[random.randint(0, len(links)-1)].attrs["href"]
    links = getLinks(newArticle)

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).