def get_excede_html(): result = 'unknown' usage_page_html = '' username, password = load_auth_info() #print "ghost initialized..." ghost = Ghost(wait_timeout=50, log_level='DEBUG', download_images=False) #Check for FAIL: no internet access try: page,resources = ghost.open('https://my.exede.net/usage') except Exception as e: print e.message result = e.message ghost.exit() return usage_page_html, result ghost.wait_for_page_loaded() if ghost.exists(".form-control.input-lg.required[name=IDToken1]"): print "Login found" else: print "Login not found" result = 'Can\'t find login box on website' ghost.exit() return usage_page_html, result print "Filling in field values" ghost.set_field_value(".form-control.input-lg.required[name=IDToken1]",username) ghost.set_field_value(".form-control.input-lg.required[name=IDToken2]",password) print "Clicking form button" ghost.click('.btn.btn-info.btn-lg.pull-right.col-lg-4[name="Login.Submit"]') print "Waiting for page to load" ghost.wait_for_page_loaded() try: if ghost.wait_for_selector('.amount-used',timeout=60): print "Found the amount used..." result = 'OK' else: print "Did not find the amount used" result = 'OK' #ghost.exit() #return usage_page_html, result except Exception as e: print e.message result = e.message usage_page_html = ghost.content.encode('ascii', 'ignore') print "Writing resulting page to disk as final_page.html" with open('final_page.html', 'w') as data_file: data_file.write(usage_page_html) ghost.exit() return usage_page_html, result