You've already forked Curso-lenguaje-python
Update url with format and url_base
This commit is contained in:
@@ -9,8 +9,7 @@ import bs4
|
||||
import requests
|
||||
|
||||
# Variables
|
||||
raiz = 'http://books.toscrape.com/catalogue/page-'
|
||||
extension = '.html'
|
||||
url_base = 'http://books.toscrape.com/catalogue/page-{}.html'
|
||||
fin_url = True
|
||||
page = 0
|
||||
lista_titulos = []
|
||||
@@ -21,7 +20,7 @@ while fin_url:
|
||||
page += 1
|
||||
page = str(page)
|
||||
|
||||
enlace = raiz + page + extension
|
||||
enlace = url_base.format(page)
|
||||
|
||||
resultado = requests.get(enlace)
|
||||
sopa = bs4.BeautifulSoup(resultado.text, 'lxml')
|
||||
@@ -31,9 +30,12 @@ while fin_url:
|
||||
|
||||
# Todos los títulos
|
||||
titulos = sopa.select('.product_pod a')
|
||||
|
||||
for title in titulos:
|
||||
if title.get('title') != None:
|
||||
lista_titulos.append(title.get('title'))
|
||||
|
||||
else:
|
||||
fin_url = False
|
||||
|
||||
print(lista_titulos)
|
||||
|
||||
Reference in New Issue
Block a user