informatica:programacion:python:modulos:beautiful_soup
Diferencias
Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previa | ||
| informatica:programacion:python:modulos:beautiful_soup [2024/06/14 16:37] – [Búsquedas] tempwin | informatica:programacion:python:modulos:beautiful_soup [2024/06/14 17:24] (actual) – [Recursos] tempwin | ||
|---|---|---|---|
| Línea 216: | Línea 216: | ||
| </ | </ | ||
| + | Recorrer una tabla buscando precios: | ||
| + | |||
| + | <code python> | ||
| + | from bs4 import BeautifulSoup | ||
| + | import requests | ||
| + | |||
| + | url = " | ||
| + | result = requests.get(url).text | ||
| + | doc = BeautifulSoup(result, | ||
| + | |||
| + | tbody = doc.tbody | ||
| + | trs = tbody.contents | ||
| + | |||
| + | prices = {} | ||
| + | |||
| + | for tr in trs[:10]: | ||
| + | for td in tr.contents: | ||
| + | name, price = tr.contents[2: | ||
| + | fixed_name = name.p.string | ||
| + | fixed_price = price.a.string | ||
| + | | ||
| + | prices[fixed_name] = fixed_price | ||
| + | | ||
| + | print(prices) | ||
| + | </ | ||
| ===== Recursos ===== | ===== Recursos ===== | ||
| * [[https:// | * [[https:// | ||
| + | * [[https:// | ||
informatica/programacion/python/modulos/beautiful_soup.1718375866.txt.gz · Última modificación: por tempwin
