Created
September 11, 2015 21:38
-
-
Save lcruz/99871e31fa2797055044 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
browser = browser() | |
browser.get("http://www.skualo.cl/ERP/login.aspx") | |
elem = browser.css("#txtIDUsuario") | |
elem.send_keys("") | |
elem = browser.css("#txtPassword") | |
elem.send_keys("") | |
elem = browser.css("#bttIngresar").click() | |
elem = browser.css("#bttContinuar").click() | |
url = "http://www.skualo.cl/ERP/FIN/RPT/rptResultadoMensual.aspx" | |
browser.get(url) | |
browser.css("#ctl00_contenido_cmbMes option[value='8']").click() | |
browser.css("#ctl00_contenido_cmbFormatoSalida option[value='XLS']").click() | |
data = [(x.get_attribute("name"), x.get_attribute("value")) for x in browser.css("form#aspnetForm select")] + \ | |
[(x.get_attribute("name"), x.get_attribute("value")) for x in browser.css("form#aspnetForm input[type=hidden]")] + \ | |
[(x.get_attribute("name"), x.get_attribute("value")) for x in browser.css("form#aspnetForm input[type=submit]") if x.get_attribute("name") != 'ctl00$contenido$bttSalir'] + \ | |
[(x.get_attribute("name"), x.get_attribute("value")) for x in browser.css("form#aspnetForm input[type=checkbox]")] | |
headers = {'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:39.0) Gecko/20100101 Firefox/39.0'} | |
cookies = dict([(x['name'], x['value']) for x in browser.get_cookies()]) | |
# Save file | |
with open('reporte.xls', 'wb') as f: | |
r = requests.post(url, data=dict(data), cookies=cookies, headers=headers) | |
f.write(r.content) | |
browser.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment