following links in python

Solutions on MaxInterview for following links in python by the best coders in the world

showing results for - "following links in python"
Cristina
25 Feb 2020
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
similar questions
queries leading to this page
following links in python