import requests
from bs4 import BeautifulSoup

def recursiveUrl(url, link, depth):
    if depth == 5:
        return url
    else:
        print(link['href'])
        page = requests.get(url + link['href'])
        soup = BeautifulSoup(page.text, 'html.parser')
        newlink = soup.find('a')
        if len(newlink) == 0:
            return link
        else:
            return link, recursiveUrl(url, newlink, depth + 1)

def getLinks(url):
    page = requests.get(url)
    soup = BeautifulSoup(page.text, 'html.parser')
    links = soup.find_all('a')
    for link in links:
        links.append(recursiveUrl(url, link, 0))
    return links

links = getLinks("http://www.reddit.com/")
print(links)
[((18, 11, 18, 28), 'requests.get', 'requests.get', ({(18, 24, 18, 27): 'url'}, {}), '(url)', False, 'import requests\n'), ((19, 11, 19, 50), 'bs4.BeautifulSoup', 'BeautifulSoup', ({(19, 25, 19, 34): 'page.text', (19, 36, 19, 49): '"""html.parser"""'}, {}), "(page.text, 'html.parser')", False, 'from bs4 import BeautifulSoup\n'), ((9, 15, 9, 47), 'requests.get', 'requests.get', ({(9, 28, 9, 46): "url + link['href']"}, {}), "(url + link['href'])", False, 'import requests\n'), ((10, 15, 10, 54), 'bs4.BeautifulSoup', 'BeautifulSoup', ({(10, 29, 10, 38): 'page.text', (10, 40, 10, 53): '"""html.parser"""'}, {}), "(page.text, 'html.parser')", False, 'from bs4 import BeautifulSoup\n')]