I was working on a solution for adamchapman on his topic here. I was able to make the option change quite easily, but downloading the file is a different story.
AutoIt Code to change select option
I reviewed the function tied to the change event. This same function is called when you click the download link. The only difference is the argument is false and true respectively. I removed the code that is executed when false as it is not relevant for the issue. It basically builds a string with the selected option value + true + symbol (Example: 5d|true|AA), then sets the value of the input that has an id ending in submitString and submits the form.
function getQuotes(download) { if(!download) showLoadingSpinner(); var data = $("[id$='ddlTimeFrame']").val(); var submitString = data + '|' + download + "|" + quoteBoxSelectedSymbol; if (!download) { <!-- Removed --> } else { $("[id$='submitString']").val(submitString); $("#getFile").submit(); } }
-
Now we move on to the form that is submitted by the getQuotes function. The input with id "quotes_content_left_submitString" is the input that will have the value set from the previous function.
<form id="getFile" method="post" action="http://www.nasdaq.com/symbol/aa/historical" lpsubdone="1"> <div class="aspNetHidden"> <input id="__VIEWSTATE" name="__VIEWSTATE" value="TRIMMED" type="hidden"> </div> <div class="aspNetHidden"> <input id="__VIEWSTATEENCRYPTED" name="__VIEWSTATEENCRYPTED" value="" type="hidden"> <input id="__EVENTVALIDATION" name="__EVENTVALIDATION" value="FslL5mK8EfHMdRmVPirjPRHx0rzoR4ZblfHZcyVf/H6sJ58PbPdR2nXwJige52KEPcse4Wp37klD+PDrLXkhysNoAbltd+CEe5ntj67kFmk=" type="hidden"> </div> <input id="quotes_content_left_submitString" name="ctl00$quotes_content_left$submitString" value="" type="hidden"> </form>
-
I believe this can be easily solved using WinHTTP, however I don't have a good understanding of that library currently. I did use Fiddler to capture the request and response that are generated when downloading the file.
Request
Response
-
I'd like to get the csv file downloaded using WinHTTP, but the main purpose of this is to learn how to use WinHTTP.