As if this isn't extremely obvious, I am a new coder.
My code works, but is quite far from ideal. I'm also not sure if there are unnecessary bits, since I've been trying to get this to work for a few days on and off, so I've started and stopped multiple times.
The goal is to have cleaner code, with a #comment on each line (unless extremely basic) so as to improve my annotation habits. Please let me know what you would do to improve it overall.
import urllib.request as ur
from bs4 import BeautifulSoup
url = str(input('Enter URL- ')) #convert input to string
html = ur.urlopen(url).read() #read html
soup = BeautifulSoup(html, "html.parser") #retrieve all of the anchor tags
Count_ = int(input('Enter count: ')) #convert input to integer
pos_1 = int(input('Enter position: ')) #convert input to integer
tags = soup('a')
final = '' #url of name list before break
curpos = ''
print('Retrieving: ', url) #prints starting point/url
count = int(Count_) + 1
while count > 1 : #starting a definite loop that goes until count is smaller than 1
pos = 0
for tag in tags :
if pos == int(pos_1) - 1 : #conditional statement regarding position
curpos = tag.get('href', None)
break
pos = pos + 1 #increases value of pos for each tag
final = curpos #
url = str(curpos) #
html = ur.urlopen(url).read()
soup = BeautifulSoup(html, "html.parser")
tags = soup('a')
count = count - 1 #for every iteration in the loop, subtract 1 from the value of count
print('Retrieving: ', final)