I'm new to python, and after doing a few tutorials, some about scraping, I been trying some simple scrapping on my own. Using beautifulsoup I manage to get data from webpages where everything has labels, but without them I'm doing a poor job.
I'm trying to get the dollar exchange rate from: http://www.bancochile.cl/cgi-bin/cgi_mone?pagina=inversiones/mon_tasa/cgi_mone
The value I'm after is highlighted in yellow
After a lot of trial and error, I manage to get the dollar exchange rate, but I think there has to be a better way.
import requests from bs4 import BeautifulSoup page = requests.get("http://www.bancochile.cl/cgi-bin /cgi_mone?pagina=inversiones/mon_tasa/cgi_mone") soup = BeautifulSoup(page.content, 'html.parser') tables = soup.find_all("table") dollar = tables.find_all("td") print(dollar.string)
Is there a better, or more correct way to do this? Also, I'm not sure if the problem is in the way I coded, or in not being able to better understand the html structure, to navigate to the information in a more efficient way.