ngskicker Posted July 12, 2013 Share Posted July 12, 2013 No more than the title above, I just want to download a file on a site, the file is in .xls format, say the URL is: https://go.xero.com/Reports/ExcelReport.aspx?reportId=aebe4549-3743-484d-bc88-906d6d277cdf&report=&statement=17e61be5-f96b-478c-8ef1-a41b0bbe33e6&attPage= when I open this url in the browser that is being logged on the site, I successfully download this file, but otherwise I will be redirected to this address: https://login.xero.com/?applicationToken=ded09319d8f9498d827149dab3f5fe78&redirectCount=0 this page is login with this form: <form action="/" id="LoginForm" method="post"><input id="fragment" name="fragment" style="display:none" type="hidden" value=""> <fieldset> <div class="field"> <label for="email">Email</label> <input autocomplete="off" autofocus="autofocus" id="email" name="userName" title="Please enter your Email address" type="email" value=""> </div> <div class="field"> <label for="password">Password</label> <input autocomplete="off" id="password" name="password" title="Please enter your Xero password" type="password"> </div> </fieldset> <div class="actions"> <a href="#" id="submitButton" class="x-btn blue main">Login</a> <input name="__RequestVerificationToken" type="hidden" value="cXNWGb318lImYLYWJdtcATK0ZJL72S2r9Xu0demAcVDtFIeoZn+LqXAIUBICXH1JzQjazcBLLzQymQ1Hu2ZMn9J/4JBZe/cNOO1WgwLWFsqUs20Y7LPPFKT7nOwbYPqpNiKvZw=="> </div> </form> I want to be able to download this file automatically without user assistance, for now i use IE to download this file (_IECreate, _IEFormElementSetValue, _IEFormSubmit) the problem with this I can't automate IE download dialog, so i need click the dialog first, anyone who cares with my problem? Link to comment Share on other sites More sharing options...
hiho Posted July 12, 2013 Share Posted July 12, 2013 Install FireBug, restart Firefox, hit 12 and navigate to https://go.xero.com/Reports/ExcelReport.aspx?reportId=aebe4549-3743-484d-bc88-906d6d277cdf&report=&statement=17e61be5-f96b-478c-8ef1-a41b0bbe33e6&attPage= Then on the Net tab take a look where the file is uploaded and use the address with Inetget Link to comment Share on other sites More sharing options...
ngskicker Posted July 12, 2013 Author Share Posted July 12, 2013 https://go.xero.com/Reports/ExcelReport.aspx?reportId=aebe4549-3743-484d-bc88-906d6d277cdf&report=&statement=17e61be5-f96b-478c-8ef1-a41b0bbe33e6&attPage= is download link, i get it from chrome download history, there is no such link in the source html, because the link is javascript onclick, Link to comment Share on other sites More sharing options...
ngskicker Posted July 12, 2013 Author Share Posted July 12, 2013 Can someone here says, this possible or imposible. Link to comment Share on other sites More sharing options...
mmfalcao Posted September 19, 2013 Share Posted September 19, 2013 it's possible Use the WinHTTP.udf for apply method post and send as a parameters the login and password and create a function to save the document. Remember you need check the navigation before that login, test many times, for you check how it works, some pages has changes in the access when you run every time, is that why you can expect timeout or another page, or the login again. Regards, mmfalcao Link to comment Share on other sites More sharing options...
trancexx Posted September 19, 2013 Share Posted September 19, 2013 (edited) Based on the data you provided it would probably be something like this:expandcollapse popup#include "WinHttp.au3" Global Const $sUserName = "YourEmail@address.com" Global Const $sPassword = "SuperSecretPassword" ; Initialize and get session handle $hOpen = _WinHttpOpen() ; Get connection handle $hConnect = _WinHttpConnect($hOpen, "login.xero.com", $INTERNET_DEFAULT_HTTPS_PORT) ; Fill login form: $sRead = _WinHttpSimpleFormFill($hConnect, _ Default, _ ; location of the form "LoginForm", _ ; id of the form "name:userName", $sUserName, _ "name:password", $sPassword) ; You can check both @error and inspect $sRead to see if login was good ;~ ConsoleWrite($sRead & @CRLF) ; Close connection handle _WinHttpCloseHandle($hConnect) ; Open new connection handle $hConnect = _WinHttpConnect($hOpen, "go.xero.com", $INTERNET_DEFAULT_HTTPS_PORT) $vXLS = _WinHttpSimpleSSLRequest($hConnect, _ Default, _ "Reports/ExcelReport.aspx?reportId=aebe4549-3743-484d-bc88-906d6d277cdf&report=&statement=17e61be5-f96b-478c-8ef1-a41b0bbe33e6&attPage=", _ Default, _ Default, _ Default, _ Default, _ 2) ; BINARY ; Close connection handle _WinHttpCloseHandle($hConnect) ; Close session handle _WinHttpCloseHandle($hOpen) ; Do whatever with this data, save to file or just print to console like I'm doing here ConsoleWrite($vXLS & @CRLF) ;$hFile = FileOpen(@DesktopDir & "\test.xls", 18) ; Binary ;FileWrite($hFile, $bXLS) ;FileClose($hFile) ;The End Edited September 20, 2013 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
ngskicker Posted February 23, 2014 Author Share Posted February 23, 2014 (edited) Based on the data you provided it would probably be something like this: expandcollapse popup#include "WinHttp.au3" Global Const $sUserName = "YourEmail@address.com" Global Const $sPassword = "SuperSecretPassword" ; Initialize and get session handle $hOpen = _WinHttpOpen() ; Get connection handle $hConnect = _WinHttpConnect($hOpen, "login.xero.com", $INTERNET_DEFAULT_HTTPS_PORT) ; Fill login form: $sRead = _WinHttpSimpleFormFill($hConnect, _ Default, _ ; location of the form "LoginForm", _ ; id of the form "name:userName", $sUserName, _ "name:password", $sPassword) ; You can check both @error and inspect $sRead to see if login was good ;~ ConsoleWrite($sRead & @CRLF) ; Close connection handle _WinHttpCloseHandle($hConnect) ; Open new connection handle $hConnect = _WinHttpConnect($hOpen, "go.xero.com", $INTERNET_DEFAULT_HTTPS_PORT) $vXLS = _WinHttpSimpleSSLRequest($hConnect, _ Default, _ "Reports/ExcelReport.aspx?reportId=aebe4549-3743-484d-bc88-906d6d277cdf&report=&statement=17e61be5-f96b-478c-8ef1-a41b0bbe33e6&attPage=", _ Default, _ Default, _ Default, _ Default, _ 2) ; BINARY ; Close connection handle _WinHttpCloseHandle($hConnect) ; Close session handle _WinHttpCloseHandle($hOpen) ; Do whatever with this data, save to file or just print to console like I'm doing here ConsoleWrite($vXLS & @CRLF) ;$hFile = FileOpen(@DesktopDir & "\test.xls", 18) ; Binary ;FileWrite($hFile, $bXLS) ;FileClose($hFile) ;The End Hi @trancexx you are really my hero, many many thanks, even after 7 months I still need this, before this I try to automate IE download, but its buggy with many IE version, Your solution works, but now the problem is the downloaded data (.xls file) is truncated I only got a few lines when I open the file on MS Excel, can you explan to me? EDIT: apparently I only get the first 5120 kb of data, Edited February 23, 2014 by ngskicker Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now