You might look at this thread:
https://www.mobileread.com/forums/sho...d.php?t=139088 to see a script that someone else wrote for downloading files to their device. I'm sure your details are different (re cookies, logins,...), but it shows you the general approach to the problem.