We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import requests from bs4 import BeautifulSoup import datetime import pandas as pd
def scrap(año, mes, url):
for i in range(1,7): try: fecha = datetime.datetime(año,mes,i) data = {'fecha': fecha.strftime('%d-%m-%y')} resp = requests.post(url, data=data) soup = BeautifulSoup(resp.text, "html.parser") break except: print('Falló en ',i) filas = soup.find_all('td', {'style' : 'padding: 1%'}) return filas
def parsear(filas): mensual = pd.DataFrame() for i in range(1, int(len(list(filas))/3)): dic = {} dic['fecha'] = filas[3i].text dic['bid'] = filas[3i+1].text dic['ask'] = filas[3*i+2].text rueda = pd.DataFrame.from_dict(dic, orient='index').transpose().set_index('fecha') rueda.index = pd.to_datetime(rueda.index, format='%d-%m-%y ') mensual = pd.concat([mensual,rueda], axis=0) return mensual
def downloadAño(año,url): tablaAnual = pd.DataFrame() for i in range(1,13): filas = scrap(año=año, mes=i,url=url) tabla = parsear(filas) tablaAnual = pd.concat([tablaAnual,tabla],axis=0) print('mes',i,'listo') tablaAnual.to_excel('blue_'+str(año)+'.xlsx') print(tablaAnual) return tablaAnual
año=2022
dolar_blue= downloadAño(año,'https://www.cotizacion-dolar.com.ar/dolar-blue-historico-'+str(año)+'.php') dolar_oficial= downloadAño(año,'https://www.cotizacion-dolar.com.ar/dolar-historico-bna-'+str(año)+'.php')
The text was updated successfully, but these errors were encountered:
No branches or pull requests
OBTENGO 2 DATAFRAME CON LOS VALORES HISTORICOS DEL DOLAR EN ARGENTINA
import requests
from bs4 import BeautifulSoup
import datetime
import pandas as pd
def scrap(año, mes, url):
def parsear(filas):
mensual = pd.DataFrame()
for i in range(1, int(len(list(filas))/3)):
dic = {}
dic['fecha'] = filas[3i].text
dic['bid'] = filas[3i+1].text
dic['ask'] = filas[3*i+2].text
rueda = pd.DataFrame.from_dict(dic, orient='index').transpose().set_index('fecha')
rueda.index = pd.to_datetime(rueda.index, format='%d-%m-%y ')
mensual = pd.concat([mensual,rueda], axis=0)
return mensual
def downloadAño(año,url):
tablaAnual = pd.DataFrame()
for i in range(1,13):
filas = scrap(año=año, mes=i,url=url)
tabla = parsear(filas)
tablaAnual = pd.concat([tablaAnual,tabla],axis=0)
print('mes',i,'listo')
tablaAnual.to_excel('blue_'+str(año)+'.xlsx')
print(tablaAnual)
return tablaAnual
año=2022
dolar_blue= downloadAño(año,'https://www.cotizacion-dolar.com.ar/dolar-blue-historico-'+str(año)+'.php')
dolar_oficial= downloadAño(año,'https://www.cotizacion-dolar.com.ar/dolar-historico-bna-'+str(año)+'.php')
The text was updated successfully, but these errors were encountered: