prueba
import requests
from bs4 import BeautifulSoup
BASE_URL = "https://www.taladrosmagneticos.cl"
PRODUCT_LIST_URL = f"{BASE_URL}/tienda/"
def get_products_from_page(url):
print(f"Obteniendo productos desde: {url}")
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
products = []
product_cards = soup.select(".product-small")
for card in product_cards:
name = card.select_one(".woocommerce-loop-product__title")
price = card.select_one(".woocommerce-Price-amount")
img = card.select_one("img")
link = card.select_one("a")
products.append({
"nombre": name.get_text(strip=True) if name else "Sin nombre",
"precio": price.get_text(strip=True) if price else "Sin precio",
"imagen": img["src"] if img else "",
"url": link["href"] if link else "",
})
return products
def get_all_products():
url = PRODUCT_LIST_URL
all_products = []
while url:
products = get_products_from_page(url)
all_products.extend(products)
# Buscar link a la siguiente página
soup = BeautifulSoup(requests.get(url).content, "html.parser")
next_page = soup.select_one(".next.page-number a")
url = next_page["href"] if next_page else None
return all_products
if __name__ == "__main__":
productos = get_all_products()
for p in productos:
print(p)