Download file using Internet Explorer COM

Get help with using AutoHotkey and its commands and hotkeys
Slada
Posts: 2
Joined: 05 Nov 2016, 19:29

Download file using Internet Explorer COM

06 Nov 2016, 05:20

Hello,

I need to download file behind login screen, is it possible to handle download using IE COM?

Code: Select all

;... create new Internet Explorer
pwb := ComObjCreate("InternetExplorer.Application")
pwb.Visible := False

;...  go to login page
pwb.Navigate("http://www.example.com/login")

;... wait for page to load
Sleep, 100
while pwb.busy or pwb.ReadyState != 4 
	Sleep, 100

;...  log me into website
pwb.document.all.email.Value :="[email protected]" ;set ID - email
pwb.document.all.password.Value :="password123" ;set ID - password

;...  go to download page
pwb.Navigate("http://www.example.com/downloads")

;... wait for page to load
Sleep, 100
while pwb.busy or pwb.ReadyState != 4 
	Sleep, 100

;... Click Download button
pwb.document.all.tags("SPAN")[41].click() 
When Explorer is visible, after clicking download button I get this download message
https://social.microsoft.com/Forums/getfile/12584/

Is it possible to download and save file (it is .csv file), when Internet Explorer is hidden?

I have tried UrlDownloadToFile - does not work, because I need to be logged in to download file
I have tried this script - https://stackoverflow.com/questions/294 ... loadtofile - At first it worked, but the session cookie expires after 30 minutes and download link changes too.

Thank you for your time.


EDIT:
Fixed it using this script - https://stackoverflow.com/questions/294 ... loadtofile

I got referer from IE using

Code: Select all

pwb.LocationURL
and I got cookies from IE using

Code: Select all

pwb.document.cookie

Code: Select all

customHeaders := {"User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"
                 ,"Cache-Control": "max-age=0"
		 ,"Referer": pwb.LocationURL
		 ,"Cookie": pwb.document.cookie}
Download(GeneratedDownloadLink,outputCSVFile,True,customHeaders,"GET")

Return to “Ask For Help”

Who is online

Users browsing this forum: A_Perry_1984, AHKStudent, aifritz, Bing [Bot], Flipeador, MannyKSoSo, Odlanir, throwaway53245 and 218 guests