1import urllib
2from BeautifulSoup import *
3
4URL = raw_input("Enter the URL:") #Enter main URL
5link_line = int(raw_input("Enter position:")) - 1 #The position of link relative to first link
6count = int(raw_input("Enter count:")) #The number of times to be repeated
7
8while count >= 0:
9 html = urllib.urlopen(URL).read()
10 soup = BeautifulSoup(html)
11 tags = soup('a')
12 print URL
13 URL = tags[link_line].get("href", None)
14 count = count - 1