# To run this, you can install BeautifulSoup
# https://pypi.python.org/pypi/beautifulsoup4
import re
import urllib
from bs4 import BeautifulSoup
import ssl
var = ""
def recorrer1(link,counta,contados):
html = urllib.urlopen(link).read()
soup = BeautifulSoup(html, "html.parser")
tags = soup('a')
c1 = 1
c2 = 1
for tag in tags:
if c1 == counta:
#print(tag.get('href', None))
html2 = urllib.urlopen(tag.get('href', None)).read()
soup2 = BeautifulSoup(html2, "html.parser")
return tag.get('href', None)
c1 = c1 + 1
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
url = raw_input('Enter URL: ')
cont2 = int(raw_input('Enter count: '))
cont1 = int(raw_input('Enter position: '))
count3 = 1
# Retrieve all of the anchor tags
#url = 'http://py4e-data.dr-chuck.net/known_by_Fikret.html'
print "Retrieving: ",url
var = recorrer1(url,cont1,cont2)
print "Retrieving: ",var
while count3 < cont2 :
print "Retrieving: ", recorrer1(var,cont1,cont2)
var = recorrer1(var,cont1,cont2)
count3 = count3 + 1
No hay comentarios
https://www.programacionparatodos.com/2019/07/ciclos-en-la-programacion-wherefor-each.html